NeuralProphet: A Time-Series Modeling Library based on Neural-Networks | by Esmaeil Alizadeh | Towards Data Science

NeuralProphet is a python library for modeling time-series data based on neural networks. It’s built on top of PyTorch and is heavily inspired by Facebook Prophet and AR-Net libraries.
From the library name, you may ask what is the main difference between Facebook’s Prophet library and NeuralProphet. According to NeuralProphet’s documentation, the added features are[1]:
Using PyTorch’s Gradient Descent optimization engine making the modeling process much faster than Prophet
Using AR-Net for modeling time-series autocorrelation (aka serial correlation)
Custom losses and metrics
Having configurable non-linear layers of feed-forward neural networks,
etc.
Based on the project’s GitHub page, the main maintainer of this project is Oskar Triebe from Stanford University with collaboration from Facebook and Monash University.
The project is in the beta phase, so I would advise you to be cautious if you want to use this library in a production environment.
Unfortunately, there is no pip or conda package for this library at the time of writing this article. You can install it by cloning the repository and installing it running pip install .. However, if you are going to use the package in a Jupyter Notebook environment, you should install their live version pip install .[live]. This will provide more features such as a live plot of train and validation loss using plot_live_loss().
git clone https://github.com/ourownstory/neural_prophet cd neural_prophet pip install .[live]
I would recommend creating a fresh environment (a conda or venv) and installing the NeuralProphet package from the new environment letting the installer take care of all dependencies (it has Pandas, Jupyter Notebook, PyTorch as dependencies).
Now that we have the package installed, let’s play!
Here, I’m using the daily climate data in Delhi from 2013 to 2017 that I found on Kaggle. First, let’s import the main packages.
import pandas as pd from neuralprophet import NeuralProphet
Then, we can read the data into a Panda DataFrame. NeuralProphet object expects the time-series data to have a date column named ds and the time-series column value we want to predict as y.
Now let’s initialize the model. Below, I’ve brought all default arguments defined for the NeuralProphet object, including additional information about some. These are the hyperparameters you can configure in the model. Of course, if you are planning to use the default variables, you can just do model = NeuralProphet().
After configuring the model and its hyperparameters, we need to train the model and make predictions. Let’s make up to a one-year prediction of the temperature.
You can simply plot the forecast by calling model.plot(forecast) as following:
The one-year forecast plot is shown above, where the time period between 2017–01–01 to 2018–01–01 is the prediction. As can be seen, the forecast plot resembles the historical time-series. It both captured the seasonality as well as the slow-growing linear trend.
You can plot the parameters by calling model.plot_parameters().
The model loss using Mean Absolute Error (MAE) is plotted below. You can also use the Smoothed L1-Loss function.
In this post, we talked about NeuralProphet, a python library that models time-series based on Neural Networks. The library uses PyTorch as a backend. As a case study, we created a prediction model for daily Delhi climate time-series data and made a one-year prediction. An advantage of using this library is its similar syntax to Facebook’s Prophet library.
You can find the Jupyter notebook for this blog post on GitHub.
Thanks for reading!
If you liked this post, you can join my mailing list here to receive more posts about Data Science, Machine Learning, Statistics, and interesting Python libraries and tips & tricks. You can also follow me on my website, Medium, or LinkedIn.
You can now install the package directly through pip install neuralprophetor pip install neuralprophet[live]. You don't need to clone the repository as suggested in the article.
[1] NeuralProphet, Documentation
[1] O. J. Triebe et al, AR-Net: A Simple Auto-Regressive Neural Network For Time-Series, (2019)
[2] https://facebook.github.io/prophet/
[3] https://github.com/ourownstory/AR-Net
Originally published at https://www.ealizadeh.com.