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

本站现有博文340篇,共被浏览1019227次

本站已经建立2719天!

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