EADST

Using SVR to Do Sales Forecasts

I used python pandas package to load the data, and sklearn package to do predictions.

# -*- coding: UTF-8 -*-
import pandas as pd

data_frame = pd.read_excel('sample.xlsx',
                         sheet_name='xdata-1')

days = data_frame['day_of_year'].unique()
# pay_time = data_frame['pay_time'].unique()
# day_of_week = data_frame['day_of_week'].unique()
# week_of_year = data_frame['month_of_year'].unique()
# act_class = data_frame['act_class'].unique()

x, y = [], []
for day in days:
    df1 = data_frame[(data_frame['day_of_year'] == day)]['num'].sum()
    df2 = data_frame[(data_frame['day_of_year'] == day)]['pay_price'].sum()
    df3 = data_frame[(data_frame['day_of_year'] == day)]['act_class'].sum()
    df4 = data_frame[(data_frame['day_of_year'] == day)]['month_of_year'].sum()
    df5 = data_frame[(data_frame['day_of_year'] == day)]['week_of_year'].sum()
    df6 = data_frame[(data_frame['day_of_year'] == day)]['day_of_month'].sum()
    df7 = data_frame[(data_frame['day_of_year'] == day)]['day_of_week'].sum()
    # x.append([day, round(df2/float(df1), 2), round(df3/float(df1), 2)])
    x.append([day, round(df2 / float(df1), 2), round(df3 / float(df1), 2),
              df4, df5, df6, df7])
    y.append(df1)

import matplotlib.pyplot as plt
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.svm import SVR
from sklearn.metrics import r2_score, mean_squared_error, mean_absolute_error, accuracy_score
np.random.seed(0)
x.extend(x[-3:])
y.extend(y[-3:])

x = np.array(x)
y = np.array(y)

clf = SVR(kernel='linear', C=20)
# x_tran, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25)


x_tran, x_test, y_train, y_test = x[:-3], x[-3:], y[:-3], y[-3:]
clf.fit(x_tran, y_train)
y_hat = clf.predict(x_test)
print(y_hat)
print("R2:", r2_score(y_test, y_hat))
print("RMSE:", np.sqrt(mean_squared_error(y_test, y_hat)))
print("MAE:", mean_absolute_error(y_test, y_hat))
# print("Accuracy: ", accuracy_score(y_test, y_hat))
r = len(x_test) + 1
# print(y_test)
plt.plot(np.arange(1,r), y_hat, 'go-', label="predict")
plt.plot(np.arange(1,r), y_test, 'co-', label="real")
plt.legend()
plt.show()

相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
Attention Tiktoken Tensor Numpy Miniforge GPTQ LLM VPN Data Conda 多进程 SQLite torchinfo logger Shortcut Git Django ResNet-50 Augmentation Password CAM BF16 NLTK Streamlit Search Linux Disk WAN LLAMA AI git 云服务器 FP64 净利润 Michelin ModelScope v2ray Breakpoint Dataset CC 强化学习 Paper FlashAttention Docker COCO Baidu IndexTTS2 WebCrawler Windows Bitcoin Quantization Video 多线程 SQL MD5 GGML Claude Excel FP32 uWSGI Freesound Use Transformers 图形思考法 SAM CSV TSV YOLO Hotel FastAPI Sklearn Heatmap llama.cpp News Hilton 音频 财报 PyCharm CTC UI 递归学习法 Ptyhon Quantize Pickle 搞笑 DeepSeek Anaconda scipy 第一性原理 Pandas Python Safetensors Pytorch CUDA Crawler FP16 BeautifulSoup Jetson 算法题 v0.dev Paddle Land Zip Permission Diagram Food Color GPT4 Jupyter Math EXCEL 阿里云 diffusers Markdown Mixtral LoRA 版权 Knowledge tqdm 证件照 FP8 ONNX PyTorch 顶会 UNIX Llama Interview Vim HuggingFace Random Domain Cloudreve PDB C++ printf Bert GIT Card Github hf Qwen2.5 Qwen2 Firewall NLP Template Translation Magnet XGBoost Ubuntu Proxy TensorFlow BTC Datetime uwsgi Distillation 关于博主 SPIE Input Algorithm Plotly 腾讯云 NameSilo Gemma QWEN Bipartite 签证 tar VSCode OpenAI Plate git-lfs SVR LeetCode PDF 公式 PIP OCR CV OpenCV mmap CLAP VGG-16 继承 HaggingFace Google Tracking transformers Logo Agent TensorRT 飞书 RGB JSON Image2Text Web CEIR InvalidArgumentError TTS Review DeepStream Clash API Qwen Animate Base64 Hungarian Bin 报税 Statistics ChatGPT Vmess LaTeX Nginx 域名 Pillow XML Website RAR GoogLeNet
站点统计

本站现有博文321篇,共被浏览768088

本站已经建立2452天!

热门文章
文章归档
回到顶部