亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python 中的 ARIMA 模型

Python 中的 ARIMA 模型

拉風的咖菲貓 2022-11-01 14:32:34
我正在使用 ARIMA 在 Python 中進行預測,以下是我的代碼:import numpy as np import pandas as pd import matplotlib.pyplot as plt from statsmodels.tsa.seasonal import seasonal_decomposefrom sklearn import datasets, linear_modelfrom sklearn.model_selection import train_test_splitHSBC = pd.read_csv('HSBC.csv', index_col = 'Date', parse_dates = True)HSBC2 = HSBC['Close']result = seasonal_decompose(HSBC2, model='multiplicative', period = 1)from pmdarima import auto_arimaimport warningswarnings.filterwarnings("ignore")stepwise_fit = auto_arima(HSBC2, start_p = 1, start_q = 1,                       max_p = 3, max_q = 3, m = 12,                       start_P = 0, seasonal = True,                       d = None, D = 1, trace = True,                       error_action ='ignore',                          suppress_warnings = True,                        stepwise = True) train = HSBC2[0:173]test = HSBC2[173:248]model = SARIMAX(train, order = (0, 1, 1), seasonal_order =(0,1,1,12)) result = model.fit()start = len(train)end = len(train) + len(test) - 1prediction = result.predict(start,end,                            typ = 'levels').rename("Predictions")  predictions.plot(legend = True) test.plot(legend = True)我很困惑為什么預測圖的 x 軸變成數字,它應該是像測試圖一樣的日期。
查看完整描述

1 回答

?
幕布斯7119047

TA貢獻1794條經驗 獲得超8個贊

如果我沒有錯,這是由于您沒有指定索引的頻率。嘗試這個:


HSBC.index = pd.date_range(freq='d', start=HSBC.index[0], periods=len(HSBC)

請注意,如果您的索引是每日間隔的,您應該頻率='d'


編輯:


所以,答案就是改變 predict 方法的參數 start 和 end 參數,例如:


start = test['Date'].iloc[0]

end = test['Date'].iloc[-1]

prediction = result.predict(start,end,

                            typ = 'levels').rename("Predictions")  


查看完整回答
反對 回復 2022-11-01
  • 1 回答
  • 0 關注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號