indexError:只有整数,切片(`:`),省略(`...
我想实现先知算法并在模型上使用我的数据集。 在拟合过程之后,我在预测过程中遇到了以下错误。 我该如何解决这个问题?
import pandas as pd
import pystan
from prophet import Prophet
df_prophet = df[['date', 'rate']]
train_df = df_prophet[:-5]
train_df.columns = ['ds', 'y']
train_df['ds']= to_datetime(train_df['ds'])
model = Prophet()
model.fit(train_df)
test_df = df_prophet[-5:][['date']]
test_list = to_datetime(test_df.date).values
forecast = model.predict(test_list)
----> 11预测= model.predict(test_list)
indexError:只有整数,切片(
:
),省略(...
), numpy.newaxis(无
)和整数或布尔数组是有效的索引
I want to implement prophet algorithm and use my dataset on the model.
After fit process i got following error in predict process.
How can i solve this problem.?
import pandas as pd
import pystan
from prophet import Prophet
df_prophet = df[['date', 'rate']]
train_df = df_prophet[:-5]
train_df.columns = ['ds', 'y']
train_df['ds']= to_datetime(train_df['ds'])
model = Prophet()
model.fit(train_df)
test_df = df_prophet[-5:][['date']]
test_list = to_datetime(test_df.date).values
forecast = model.predict(test_list)
---> 11 forecast = model.predict(test_list)
IndexError: only integers, slices (
:
), ellipsis (...
),
numpy.newaxis (None
) and integer or boolean arrays are valid indices
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个很好的尝试。您只需要进行一些调整。
Prophet
需要一个数据帧。Prophet
模型和预测器需要标记为ds
和y
的列,并且您在拆分数据帧后更改列名称,因此您的测试部分没有重命名列。试试这个:
It's a nice attempt. You just need a few tweaks.
to_datetime(test_df.date).values
you were creating a numpy array instead of a dataframe.Prophet
expects a dataframe.Prophet
model and predictor expects columns labeledds
andy
and you're changing the column names after you split the dataframe, so your test part isn't getting the columns renamed.pystan
since the Prophet module is built on it already.Try this: