隐马尔可夫模型 - 滚动窗口预测。错误:索引 1 超出尺寸 1 的轴 0 的范围

发布于 2025-01-12 15:09:37 字数 1036 浏览 0 评论 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)

Data before interpolations

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只为一人 2025-01-19 15:09:37

好的,我能够修复它。我的错误是我对预测进行了索引(每次迭代只有一行值)。我通过将预测附加到我的变量来修复它。

    forecasted_variables.append(forecast)
    forecasted_activepower.append(forecast[0,0])

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.

    forecasted_variables.append(forecast)
    forecasted_activepower.append(forecast[0,0])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文