隐马尔可夫模型 - 滚动窗口预测。错误:索引 1 超出尺寸 1 的轴 0 的范围
我正在制作一个隐马尔可夫模型,一次预测一个值(滚动窗口)。但是,每次运行循环并尝试保存预测值时,我都会收到错误。
循环内的 Forecasted_variables 给出以下错误:“索引 1 超出大小为 1 的轴 0 的范围”。我尝试将 Forecasted_variables 制作为一个包含随机数的数组,其大小为我需要的(1008,4)。我还尝试将其设为空列表并附加我需要的值,但出现相同的错误。
在每次迭代中,我都会更新名为历史记录的变量中的训练数据。该循环应运行 1008 次,每次都将预测值保存在 Forecasted_variables 中。
###Rolling window
forecasted_activepower=[]
forecasted_variables=[]
test_activepower=test_data[:,0]
train_activepower=features[:,0]
features_model = GaussianHMM(n_components=4)
history = features.tolist()
for t in range(test_activepower.shape[0]):
features_model.fit(history)
forecast,pred_states=features_model.sample(1) #forecast holds the prediction for all the
variables
forecasted_variables=forecast[t,:]
forecasted_activepower=forecast[t,0]
history.append(test_data[t,:]) # history is used as the data for the model.
print(forecasted_activepower)
I am making a Hidden Markov Model that predicts one value at a time (rolling window). However I keep getting an error every time I run my loop and try to save the predicted value.
The forecasted_variables inside the loop gives me the following error: "index 1 is out of bounds for axis 0 with size 1". I tried making forecasted_variables an array with random numbers with the size I need (1008,4). I also tried making it an empty list and appending the values I need but I get the same error.
In every iteration I am updating the training data in the variable called history. The loop should run 1008 times and each time save the predicted values inside forecasted_variables.
###Rolling window
forecasted_activepower=[]
forecasted_variables=[]
test_activepower=test_data[:,0]
train_activepower=features[:,0]
features_model = GaussianHMM(n_components=4)
history = features.tolist()
for t in range(test_activepower.shape[0]):
features_model.fit(history)
forecast,pred_states=features_model.sample(1) #forecast holds the prediction for all the
variables
forecasted_variables=forecast[t,:]
forecasted_activepower=forecast[t,0]
history.append(test_data[t,:]) # history is used as the data for the model.
print(forecasted_activepower)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我能够修复它。我的错误是我对预测进行了索引(每次迭代只有一行值)。我通过将预测附加到我的变量来修复它。
Ok, I was able to fix it. My mistake was that I was indexing forecast (which only had one row of values for every iteration). I fixed it by appending forecast to my variables.