我使用ExponentialSmoothing
(statsmodels
)中的Version: 0.10.1
来拟合某些数据并进行预测。为了便于使用,在设置配置时,我编写了一个函数exp_smoothing_forecast
,该函数接收np array
的数据,配置列表([trend, damped, seasonal, seasonal_periods, use_boxcox, remove_bias]
)和periods
的数量进行预测。
from statsmodels.tsa.holtwinters import ExponentialSmoothing
def exp_smoothing_forecast(data, config, periods):
'''
Perform Holt Winter’s Exponential Smoothing forecast for periods of time.
'''
t,d,s,p,b,r = config
# define model
model = ExponentialSmoothing(np.array(data), trend=t, damped=d, seasonal=s, seasonal_periods=p)
# fit model
model_fit = model.fit(use_boxcox=b, remove_bias=r)
# make one step forecast
return model_fit.forecast(periods)
我使用的数据是每周一次。经过一些培训后,我找到了最佳配置,并尝试在整个数据上使用它们。
data_1 = [21725.64924, 20826.08817, 26329.99691, 14830.32665, 18169.88488, 19982.91422, 17257.78265, 22538.69626, 18838.27302, 20139.47118, 19080.43343, 15828.84575, 13451.70394, 17548.52795, 14860.06954, 13985.35829, 13260.54788, 12322.06192, 10867.44784, 10853.70009, 13341.73247, 13263.60543, 14649.75235, 14326.58656, 22039.07262, 22888.31507, 32067.63148, 21074.63281, 53075.97138, 16345.24709, 17051.97335, 18658.77237, 21884.1406 , 21657.54719, 21223.70341, 19344.71704, 23775.96044, 22271.27948, 21468.25012, 18073.62045, 9644.77351, 12727.3657 , 15356.19687, 15448.17014, 14723.84147, 17009.4649 , 16092.80642, 16419.31814, 16171.54582, 17271.33481, 21320.07636, 21296.02374, 23199.74761, 16639.21095, 21113.53543, 22749.2432 , 19140.13832, 31088.52782, 16078.59607, 18998.75585, 17151.11463, 16145.82339, 16727.5124 , 16003.41356, 14249.88642, 15841.52938, 13694.78793, 14715.99812, 14128.37359, 13356.26061, 12474.46796, 13246.16726, 13539.81145, 12930.23627, 14233.11001, 16607.7259 , 18365.03853, 20228.55651, 19625.64057, 20626.35991, 51911.0478 , 16432.92248, 18310.47551, 20430.6701 , 26044.62524, 22668.80716, 25020.77289, 23960.46101, 26476.84115, 19499.50768, 23096.5695 , 20812.98895, 8688.23701, 11360.55672, 13862.82367, 17024.09926, 14096.92062, 14283.55523, 16212.13182, 14819.90843, 16950.35181, 16083.05382, 16607.61269, 21116.02172, 19595.84582, 21126.61918, 21906.62752, 19216.92105, 16382.74362, 16425.23783, 21322.25379, 25429.74081, 19949.7062 , 18469.8872 , 19349.82817, 15669.9687 , 12194.87496, 32376.36077, 13010.62105, 12507.4141 , 11235.50094, 11312.38597, 9698.98942, 10099.33959, 11131.35398, 12235.7158 , 13335.16512, 11724.92757, 16637.36082, 19430.46408, 22844.0694 , 19945.1951 , 44117.41448, 17506.60708, 17381.30709, 15527.95481, 18537.75849, 19760.73208, 22897.52474, 19696.13375, 18927.47444, 22095.42535, 28570.44237, 16710.312 , 7929.1563 , 9383.84275, 11429.63802, 16010.66023, 12717.17012, 12528.87624, 13020.62612, 14404.17851, 19988.99529, 12783.10448, 18541.92333, 15705.89736, 10150.17117, 9778.30207, 22733.63259, 19276.8964 , 16456.28818, 22112.49009, 17702.4329 , 19155.04909, 16150.12167]
data_2 = [ 466723, 452418, 617826, 326684, 395736, 432655, 373109, 510443, 447645, 490145, 473106, 395717, 318162, 448422, 358116, 324310, 305897, 281990, 241155, 241016, 293771, 281642, 307895, 302873, 449448, 455749, 638509, 419042, 1083541, 308940, 333450, 358659, 424403, 414559, 401659, 374299, 475147, 424921, 417545, 355535, 197972, 266886, 327671, 340291, 325005, 387430, 353811, 354566, 353035, 372316, 465626, 460496, 499137, 357643, 462463, 546774, 457630, 755817, 375498, 477250, 421423, 392857, 415778, 409323, 355134, 403246, 332000, 371962, 346441, 327155, 313235, 342809, 341676, 301465, 337626, 370560, 394997, 429656, 412259, 406436, 1046463, 316611, 362318, 385388, 498224, 439668, 488849, 453815, 525870, 385304, 460586, 413856, 172720, 230966, 279383, 356115, 283973, 294327, 344245, 312181, 366841, 350318, 353869, 459447, 425272, 474133, 491659, 428531, 359783, 381855, 493805, 573676, 462372, 426205, 450398, 386455, 290877, 829583, 326638, 308343, 262156, 254527, 228484, 234804, 248274, 260784, 279731, 252299, 349873, 379531, 450056, 388944, 869849, 317120, 331701, 294900, 343365, 365744, 421099, 360206, 351678, 418177, 550871, 327995, 157403, 183336, 226609, 333601, 261049, 260766, 270743, 303745, 413120, 267795, 394175, 333527, 223721, 224568, 536792, 473902, 405797, 569279, 450162, 483895, 426864]
fcast_1 = exp_smoothing_forecast(data_1, ['add', False, 'mul', 52, False, False], 52)
fcast_2 = exp_smoothing_forecast(data_2, ['mul', True, 'mul', 52, False, False], 52)
每次的预测结果看起来都很好并且保持一致,但是尝试执行ConvergenceWarning
时我得到了fcast_2
。
D:\Anaconda3\envs\tsa_course\lib\site-packages\statsmodels\tsa\holtwinters.py:712: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.
ConvergenceWarning)
有人可以告诉我此警告的原因是什么?