我使用 ARIMA 来拟合数值并将其保存为 pickle 文件。之后,使用 pickle 文件来进行样本外预测。然而,在获取样本预测时,我遇到了以下错误:无法将 ufunc subtract 的输出从 dtype(‘float64’) 转换为 dtype(‘int64’),转换规则为 ‘same_kind’。
def forecast_fit(df): series=df X = series.values train=X model = ARIMA(X, order=(1,0,1)) model_fit = model.fit(disp=0) model_fit.save('model.pkl')forecast_fit(df)#Out of sample forecastsloaded = ARIMAResults.load('model.pkl)forecast = loaded.forecast(steps=17)[0] #error_occurs_heredf=pd.DataFrame(forecast, columns=[i+'_hat'])
df 包含以下数据:https://docs.google.com/spreadsheets/d/14W77ra-nQYqvDN8wSPhhiN11lBnob6ZW0UVevQ5orKk/edit?usp=sharing
我附上了数据,因为错误就发生在这个样本上,其余变量(我在许多其他变量上重复此操作)不会产生此错误。
回答:
看起来 statsmodels 的 ARIMA 会抛出错误,因为它没有明确地将整数转换为浮点数。如果我尝试将数据转换为浮点数,statsmodels 就能正常工作。
X = X.astype('float32')
这已经在 Github 上被报告为一个bug。