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

本站现有博文338篇,共被浏览977491次

本站已经建立2690天!

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