Created
December 16, 2020 15:52
-
-
Save AmolMavuduru/9d288d0c2d812a85955aa00a4e946adf to your computer and use it in GitHub Desktop.
Code for my Medium article demonstrating how to use NeuralProphet
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
def plot_forecast(model, data, periods, historic_pred=True, highlight_steps_ahead=None): | |
""" plot_forecast function - generates and plots the forecasts for a NeuralProphet model | |
- model -> a trained NeuralProphet model | |
- data -> the dataframe used for training | |
- periods -> the number of periods to forecast | |
- historic_pred -> a flag indicating whether or not to plot the model's predictions on historic data | |
- highlight_steps_ahead -> the number of steps ahead of the forecast line to highlight, used for autoregressive models only""" | |
future = model.make_future_dataframe(data, | |
periods=periods, | |
n_historic_predictions=historic_pred) | |
forecast = model.predict(future) | |
if highlight_steps_ahead is not None: | |
model = model.highlight_nth_step_ahead_of_each_forecast(highlight_steps_ahead) | |
model.plot_last_forecast(forecast) | |
else: | |
model.plot(forecast) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment