简单指数法

2022-05-29 10:35:30 浏览数 (1)

代码语言:javascript复制
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn.metrics import mean_squared_error
from math import sqrt
from statsmodels.tsa.api import SimpleExpSmoothing
plt.rcParams['font.sans-serif']=['SimHei']
df=pd.read_csv('C:/Users/xpp/Desktop/data.csv',nrows=11856)
#创建训练和测试集
train=df[0:10300]
test=df[10300:]
#数据聚合
df['Timestamp']=pd.to_datetime(df['Datetime'],format='%d-%m-%Y %H:%M')#4位年用Y,2位年用y
df.index=df['Timestamp']
df=df.resample('D').mean()#按天采样,计算均值
train['Timestamp']=pd.to_datetime(train['Datetime'],format='%d-%m-%Y %H:%M')
train.index=train['Timestamp']
train=train.resample('D').mean()
test['Timestamp']=pd.to_datetime(test['Datetime'],format='%d-%m-%Y %H:%M')
test.index=test['Timestamp']
test=test.resample('D').mean()
#rms=sqrt(mean_squared_error(test.Count,y_hat_exp_avg.SES))
#print("SES",rms)
#绘图
train.Count.plot(figsize=(15,8),title='日数据',fontsize=14)
test.Count.plot(figsize=(15,8),title='日数据',fontsize=14)
y_hat_exp_avg=test.copy()
fit=SimpleExpSmoothing(train.Count).fit(smoothing_level=0.6,optimized=False)
y_hat_exp_avg['SES']=fit.forecast(len(test))
train.Count.plot(figsize=(16,10),title='简单指数法',fontsize=14)
test.Count.plot(figsize=(16,10),title='简单指数法',fontsize=14)
y_hat_exp_avg.SES.plot(figsize=(16,10),title='简单指数法',fontsize=14)
plt.legend(loc='best')
plt.show()

算法:简单指数法是将所有数据考虑在内,同时给数据赋予不同的权重。

文献:Shami, R. G. . (1998). Exponential Smoothing Methods of Forecasting and General ARMA Time Series Representations. Monash University, Department of Econometrics and Business Statistics.

Fomin, I. . , & Chervon, S. . . (2022). New method of exponential potentials reconstruction based on given scale factor in phantonical two-field models.

0 人点赞