【问题标题】:SARIMAX Rolling Window with exogen Variables带有外生变量的 SARIMAX 滚动窗口
【发布时间】:2022-01-18 04:06:03
【问题描述】:

目前我正在尝试使用外部变量在 python 中构建 SARIMAX 模型。 不幸的是,我收到此错误:“无法使用灵活类型执行减少”

# Function for Rolling Forecast with Sarima
def rolling_forecast(traindata,test_data, Modell_order = None , Sarima_order = None, eliminate_0 = True, exogen= None, exogen_test=None):
    history = [x for x in traindata]
    history_exogen = [x for x in exogen]
    predictions = list()
  
    for t in range(len(test_data)):
        Sarima_Modell_same = SARIMAX(history,order = Modell_order ,seasonal_order= Sarima_order, exog=history_exogen)
        model_fit = Sarima_Modell_same.fit()
        output = model_fit.forecast(steps = 1,exog=history_exogen)
        
        yhat = output[0]
        obs = test_data[t]
        obs_ex = exogen_test[t]
        predictions.append(yhat)
        history.append(obs)
        history_exogen.append(obs_ex)
        #print('predicted=%f, expected=%f' % (yhat, obs))
    
    series_predicted = pd.Series(predictions, dtype='float64')
    series_predicted.index = test_data.index

    if eliminate_0 is True:
        # Eliminate 0 values --> (for differenced Time Series not applyable because of negativ values)
        series_predicted = series_predicted.apply(lambda x : x if x > 0 else 0)
        test_data.plot()
        series_predicted.plot(color = 'red')
    else:
        test_data.plot()
        series_predicted.plot(color = 'red')

    #print(sqrt(mean_squared_error(test_data, series_predicted)))
    

    
Is there any way to do this?

【问题讨论】:

标签: python time-series statsmodels forecasting


【解决方案1】:

关于多变量部分的更多信息。如果没有 exogen 变量,它可以工作,但如果我尝试包含它,则会出现错误。 将不胜感激。

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2020-08-06
  • 2018-06-25
  • 1970-01-01
  • 2018-07-22
  • 2013-01-21
  • 1970-01-01
  • 2021-03-11
  • 2020-07-12
  • 2021-12-03
相关资源
最近更新 更多