简体   繁体   English

如何为数据框的每一列运行ARIMA模型?

[英]How to run ARIMA model for each column of a dataframe?

I´m predicting the prices for a good in 5 regions. 我正在预测5个地区的商品价格。 The data is organized as a Pandas data frame. 数据被组织为熊猫数据框。

When I run autoARIMA for each column apart, it is fine (eg, for data_frame["Region_name"] ). 当我为每列分开运行autoARIMA时,这很好(例如,对于data_frame["Region_name"] )。

def __trainArima(self, actual_values, periods):
     fitted_model = pm.auto_arima(actual_values, start_p=3, 
                                 start_q=2,
                                 max_p=3, max_q=3, m=12,
                                 start_P=0, seasonal=True,
                                 d=1, D=1, trace=True,
                                 error_action='ignore',
                                 suppress_warnings=True,  
                                 stepwise=True) 
     return fitted_model.predict(n_periods=periods)

__trainArima(data_frame, 12)

However, I want to run it at once for all the 5 columns, having an output as a data frame of 5 columns for each region of predictions for the next 12 month. 但是,我想一次对所有5列都运行它,对于下一个12个月的每个预测区域,将其输出作为5列的数据框。 Is that possible? 那可能吗?

如果您不相信自己的列是相关的,则可以遍历每个列并运行ARIMA,然后合并预测。

To elaborate, you could loop though like this: 详细来说,您可以像这样循环:

import pandas as pd

results = []
cols = []
for i in data_frame.columns:
    cols.append(i)
    result = __trainArima(test[i])
    results.append(result)

output = (pd.DataFrame(results)).T
output.columns=cols

that will output a data frame with your predictions under the same column names as they appear in the original dataframe. 它将输出一个数据框,其中的预测与原始数据框中显示的列名称相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM