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

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

本站已经建立2493天!

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