1

我的问题很简单,我知道我遗漏了一些非常明显的东西,我只是不知道它是什么......

我对 Holt-Winters 的测试预测结果为 NaN,我不知道为什么。有人可以帮忙吗?

我正在使用 Jupyter Notebook,并尝试使用 Holt-Winters 方法预测一个 SKU 的销售。我什至使用

这是我使用的代码:

# Import the libraries needed to execute Holt-Winters

import pandas as pd
import numpy as np
%matplotlib inline

df = pd.read_csv('../Data/M1045_White.csv',index_col='Month',parse_dates=True)

# Set the month column as the index column

df.index.freq = 'MS'
df.index

df.head()

df.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 48 entries, 2015-05-01 to 2019-04-01
Freq: MS
Data columns (total 7 columns):
Sales       48 non-null int64
EWMA12      48 non-null float64
SES12       47 non-null float64
DESadd12    47 non-null float64
DESmul12    47 non-null float64
TESadd12    48 non-null float64
TESmul12    12 non-null float64
dtypes: float64(6), int64(1)
memory usage: 3.0 KB

from statsmodels.tsa.holtwinters import SimpleExpSmoothing

# Train Test Split

train_data = df.iloc[:36] # Goes up to but not including 36
test_data = df.iloc[12:]

# Fit the Model

fitted_model = exponentialSmoothing(train_data['Sales'],trend='mul',seasonal='mul',seasonal_periods=12).fit()

test_predictions = fitted_model.forecast(12).rename('HW M1045 White Forecast')

test_predictions

Here is the output of my predictions:

2018-05-01   NaN
2018-06-01   NaN
2018-07-01   NaN
2018-08-01   NaN
2018-09-01   NaN
2018-10-01   NaN
2018-11-01   NaN
2018-12-01   NaN
2019-01-01   NaN
2019-02-01   NaN
2019-03-01   NaN
2019-04-01   NaN
Freq: MS, Name: HW M1045 White Forecast, dtype: float64

有人可以指出我可能错过了什么吗?这似乎是一个简单的解决方案的简单问题,但它踢我的屁股。

谢谢!

4

2 回答 2

1

答案与seasonal_periods设置为 的变量有关12。如果将其更新为,6则预测会产生实际值。我不是指数平滑方面的统计专家,无法理解为什么会这样。

于 2019-05-28T23:56:47.877 回答
0

原因:

您的训练数据包含一些 NaN,因此无法建模或预测。

查看每列的非空值计数,它是不一样的。

df.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 48 entries, 2015-05-01 to 2019-04-01
Freq: MS
Data columns (total 7 columns):
Sales       48 non-null int64
EWMA12      48 non-null float64
SES12       47 non-null float64
DESadd12    47 non-null float64
DESmul12    47 non-null float64
TESadd12    48 non-null float64
TESmul12    12 non-null float64
dtypes: float64(6), int64(1)
memory usage: 3.0 KB

检查数据框中是否有任何缺失值

df.isnull().sum()

解决方案:

在您的情况下,在训练模型之前需要进行缺失值处理。

于 2021-12-10T17:39:39.933 回答