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

本站现有博文323篇,共被浏览799724

本站已经建立2498天!

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