0% found this document useful (0 votes)
170 views18 pages

How To Use Facebooks Neuralprophet and Why It Is So Powerful

The document provides instructions and examples for using the NeuralProphet library to fit time series forecasting models. It shows how to install NeuralProphet, load and prepare weather and stock market data, fit models to the data with different parameters, and plot forecasts against historic values. Specifically, it demonstrates fitting models to daily rainfall and S&P 500 stock price data, comparing forecasts from models with and without yearly seasonality, and adding US holiday effects to one of the S&P 500 models.

Uploaded by

ante mitar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
170 views18 pages

How To Use Facebooks Neuralprophet and Why It Is So Powerful

The document provides instructions and examples for using the NeuralProphet library to fit time series forecasting models. It shows how to install NeuralProphet, load and prepare weather and stock market data, fit models to the data with different parameters, and plot forecasts against historic values. Specifically, it demonstrates fitting models to daily rainfall and S&P 500 stock price data, comparing forecasts from models with and without yearly seasonality, and adding US holiday effects to one of the S&P 500 models.

Uploaded by

ante mitar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

pip install neuralprophet

pip install neuralprophet[live]

git clone https://github.com/ourownstory/neural_prophet.git


cd neural_prophet
pip install .
import pandas as pd
from neuralprophet import NeuralProphet

data = pd.read_csv('./data/seattleWeather_1948-2017.csv')
data.head(10)

prcp_data = data.rename(columns={'DATE': 'ds', 'PRCP': 'y'})[['ds',


'y']]
model = NeuralProphet()
metrics = model.fit(prcp_data, validate_each_epoch=True,
valid_p=0.2, freq='D',
plot_live_loss=True, epochs=10)
future = model.make_future_dataframe(prcp_data, periods=365*5)
forecast = model.predict(future)
forecasts_plot = model.plot(forecast)A
import pandas_datareader as pdr
from datetime import datetime
import matplotlib.pyplot as plt
%matplotlib inline

start = datetime(2010, 12, 13)


end = datetime(2020, 12, 11)

sp500_data = pdr.get_data_fred('sp500', start, end)


plt.figure(figsize=(10, 7))
plt.plot(sp500_data)
plt.title('S&P 500 Prices')
sp500_data = sp500_data.reset_index().rename(columns={'DATE': 'ds',
'sp500': 'y'}) # the usual preprocessing routine

model = NeuralProphet(n_changepoints=100,
trend_reg=0.05,
yearly_seasonality=False,
weekly_seasonality=False,
daily_seasonality=False)

metrics = model.fit(sp500_data, validate_each_epoch=True,


valid_p=0.2, freq='D',
plot_live_loss=True,
epochs=100)
plot_forecast(model, sp500_data, periods=60)
model = NeuralProphet(n_changepoints=100,
trend_reg=0.5,
yearly_seasonality=True,
weekly_seasonality=False,
daily_seasonality=False)

metrics = model.fit(sp500_data, validate_each_epoch=True,


valid_p=0.2, freq='D',
plot_live_loss=True,
epochs=100)
plot_forecast(model, sp500_data, periods=60,
historic_predictions=True)

plot_forecast(model, sp500_data, periods=60,


historic_predictions=False, highlight_steps_ahead=60)
model = NeuralProphet(
n_forecasts=60,
n_lags=60,
n_changepoints=100,
yearly_seasonality=True,
weekly_seasonality=False,
daily_seasonality=False,
batch_size=64,
epochs=100,
learning_rate=1.0,
)

model.fit(sp500_data,
freq='D',
valid_p=0.2,
epochs=100)

plot_forecast(model, sp500_data, periods=60,


historic_predictions=True)

plot_forecast(model, sp500_data, periods=60,


historic_predictions=False, highlight_steps_ahead=60)
model = model.add_country_holidays("US", mode="additive",
lower_window=-1, upper_window=1)
plot_forecast(model, sp500_data, periods=60, historic_predictions=False,
highlight_steps_ahead=60)

You might also like