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

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

本站已经建立2628天!

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