Reputation: 1301
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
Upvotes: 0
Views: 1414
Reputation: 209
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 labeled ds
and y
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:
import pandas as pd
from prophet import Prophet
df_prophet = df[['Date', 'Volume']]
df_prophet.columns = ['ds', 'y']
train_df = df_prophet[:-5]
train_df['ds']= pd.to_datetime(train_df['ds'])
model = Prophet()
model.fit(train_df)
test_df = df_prophet[-5:][['ds']]
forecast = model.predict(test_df)
forecast
Upvotes: 1