max_p=3, max_q=3, m=12, start_P=0, seasonal=True, d=1, D=1, trace=True, error_action='ignore', suppress_warnings=True) # fitting the model model.fit(training) # using the model to make predictions forecast = model.predict(n_periods=248) forecast = pd.DataFrame(forecast, index=test.index, columns=['Prediction']) # RMSE rms = np.sqrt( np.mean( np.power((np.array(test['Close']) - np.array(forecast['Prediction'])), 2))) print(rms) # plot plt.plot(train['Close']) plt.plot(test['Close']) plt.plot(forecast['Prediction']) plt.show()
# importing data_processing from data_processing import train, test, np, plt # moving average # create predictions for test set # check RMSE using the actual values preds = [] for i in range(0, test.shape[0]): a = train['Close'][len(train) - 248 + i:].sum() + sum(preds) b = a / 248 preds.append(b) # checking RMSE value rms = np.sqrt(np.mean(np.power((np.array(test['Close']) - preds), 2))) print('\n RMSE value on test set:') print(rms) # plot test['Predictions'] = preds plt.plot(train['Close']) plt.plot(test[['Close', 'Predictions']]) plt.show()
new_data['Date'] = pd.to_datetime(new_data.Date, format='%Y-%m-%d') new_data.index = new_data['Date'] # preparing data new_data.rename(columns={'Close': 'y', 'Date': 'ds'}, inplace=True) # splitting into training and testing data train = new_data[:987] test = new_data[987:] # Creating and fitting the model model = Prophet() model.fit(train) # predictions close_prices = model.make_future_dataframe(periods=len(test)) forecast = model.predict(close_prices) # RMSE forecast_test = forecast['yhat'][987:] rms = np.sqrt( np.mean(np.power((np.array(test['y']) - np.array(forecast_test)), 2))) print(rms) # plot test['Predictions'] = forecast_test.values plt.plot(train['y']) plt.plot(test[['y', 'Predictions']]) plt.show()