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

本站现有博文332篇,共被浏览900123

本站已经建立2601天!

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