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

本站现有博文320篇,共被浏览759183

本站已经建立2427天!

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