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

本站现有博文333篇,共被浏览917303

本站已经建立2622天!

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