Created
March 23, 2018 18:06
-
-
Save freedomtowin/fd0ac7b491aff15eea6caab027bc58df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fbprophet import Prophet | |
fbprophet_df = big_df[['visit_date','visitors']].groupby('visit_date').sum().reset_index() | |
fbprophet_df.columns = ['ds','y'] | |
train = fbprophet_df[:int(len(fbprophet_df)*0.7)] | |
valid = fbprophet_df[int(len(fbprophet_df)*0.7):] | |
m = Prophet(daily_seasonality=True,yearly_seasonality=True) | |
m.fit(train); | |
future = m.make_future_dataframe(periods=len(valid)) | |
forecast = m.predict(future) | |
y_pred = forecast['yhat'][:int(len(fbprophet_df)*0.7)] | |
plt.plot(y_pred) | |
plt.plot(train['y']) | |
plt.show() | |
sse = np.sum((y_pred-train[['y']].values.flatten())**2) | |
sst = np.sum((np.mean(train[['y']].values.flatten())-train[['y']].values.flatten())**2) | |
y_pred = forecast['yhat'][int(len(fbprophet_df)*0.7):] | |
plt.plot(y_pred) | |
plt.plot(valid['y']) | |
plt.show() | |
sse = np.sum((y_pred-valid[['y']].values.flatten())**2) | |
sst = np.sum((np.mean(valid[['y']].values.flatten())-valid[['y']].values.flatten())**2) | |
print('validation r-squared:',1-sse/sst) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment