Visualizing NeuralProphet’s Forecasts#
This notebook demonstrates what different plotting options are available in NeuralProphet.
As different plotting backends have different advantages and disadvantages, NeuralProphet supports multiple plotting backends: *
plotly: Interactive plots, but can be slow for large datasets and cannot be displayed in the docs version *
plotly-static: Static plots to be displayed in the docs version *
plotly-resampler: Interactive plots, that are faster for large datasets, but might not properly vizualise in some evnironments *
matplotlib: Static plots, but will be deprecated
Let’s start with the same model as in the tutorials:
import pandas as pd from neuralprophet import NeuralProphet, set_log_level # Disable logging messages unless there is an error set_log_level("ERROR") # Load the dataset from the CSV file using pandas df = pd.read_csv("https://github.com/ourownstory/neuralprophet-data/raw/main/kaggle-energy/datasets/tutorial04.csv") # Reduce the dataset to two years to better show the data df = df.iloc[-365 * 2 :] # Model and prediction m = NeuralProphet( # Disable trend changepoints n_changepoints=10, # Disable seasonality components yearly_seasonality=True, weekly_seasonality=True, daily_seasonality=True, n_lags=10, ) m.add_lagged_regressor("temperature") m.set_plotting_backend("plotly-static") metrics = m.fit(df) forecast = m.predict(df)
Plot the forecast#
Plot the forecast of the model and the actual data.
Plot the components#
Plot the components of the forecast, i.e. trend, seasonality, and holidays. You can choose to plot all components or only a subset with ``components`. <https://neuralprophet.com/code/forecaster.html?highlight=lot_parameters#neuralprophet.forecaster.NeuralProphet.plot_parameters>`__
Plot the parameters#
To get a better understanding of the model, you can plot the parameters of the model. As in
plot_components, you can choose to plot all parameters or only a subset of parameters.
Plotting of multiple forecasts#
Neuralprophet can generate multiple step ahead forecasts by specifying the
# Model and prediction m = NeuralProphet( # Disable trend changepoints n_changepoints=10, # Disable seasonality components yearly_seasonality=True, weekly_seasonality=True, daily_seasonality=True, n_lags=10, n_forecasts=10, ) m.add_lagged_regressor("temperature") m.set_plotting_backend("plotly-static") metrics = m.fit(df) forecast = m.predict(df)
If we plot our forecast as before, all step ahead forecasts will be plotted. However, we can also plot each step ahead forecast individually.
Trend, seasonality, and holidays are the same for all step ahead forecasts, so they are only plotted once. But autoregression and lagged regressors are different for each step ahead forecast. If
forecast_in_focus is not specified, the components plot shows the component share to each forecast step in different colors. If
forecast_in_focus is specified, the components plot shows the component share of the specified forecast step.
# Show only last 20 days to better see the components m.plot_components(forecast[-20:])
As the parameters are the same for all step ahead forecasts, they are only plotted once.