7 libraries that help in time-series problems | by Pratik Gandhi | Towards Data Science

Time series problems are one of the toughest problems to solve in data science. Traditional methods that are time-aware like ARIMA, SARIMA are great but lately they have largely been accompanied by the non-time aware and robust machine learning algorithms like XGBoost, LigthGBM, and so forth because of need and proven successful track records. However, using these methods require extensive data preparation like removing periodicity, removing trend from the target and engineering features like rolling window features, lag features, etc. to prepare the final dataset.
To gain better accuracy we need to develop complex models and the work can be quite extensive. Therefore, it is better to leverage some of the automation that is already developed/creating by the Machine Learning community. Below are some of the packages which are really helpful in solving time series problems.
tsfresh is a fantastic python package that can automatically calculate a large number of time series features.
Let's understand how tsfresh can be implemented by taking a standard dataset of Airline passengers:
The data needs to/will be formatted in a format something like below:
From the output above we see that almost ~800 features are created. tsfresh also helps in feature selection based on p-value. Check out the documentation for more details.
There is an exhaustive list of all the features that are calculated using tsfresh which can found here.
Github: https://github.com/blue-yonder/tsfresh
Documentation: https://tsfresh.readthedocs.io/en/latest/index.html
AutoTS is an automated time series forecasting library that can train multiple time series models using straightforward code. AutoTS means Automatic Time Series.
Some of the best features of this library are:
It uses genetic programming optimization to find optimal time series forecasting model.
Provides lower and upper confidence interval forecast values.
It trains diverse models like naive, statistical, machine learning as well as deep learning models
It can also perform automatic ensembling of best models
It also has the ability to handle messy data by learning optimal NaN imputation and outlier removal
It can run both univariate and multivariate time series
Let us take Apple Stocks dataset and understand more in detail:
model = AutoTS(forecast_length=40, frequency='infer', 
               ensemble='simple', drop_data_older_than_periods=100)
model = model.fit(df, date_col='Date', value_col=' Close/Last', id_col=None)
This will run hundreds of models. You will see in the output pane the variety of models that run. Lets see how the model predicts :
prediction = model.predict()
forecast = prediction.forecast
print("Stock Price Prediction of Apple")
print(forecast)
Github: https://github.com/winedarksea/AutoTS
Documentation: https://winedarksea.github.io/AutoTS/build/html/source/tutorial.html
3. Prophet:
Prophet is a well-known time series package developed by the research team at Facebook with its first release in 2017. It works well with data that has strong seasonal effects and several seasons of historical data. It is highly user-friendly and customizable, with minimum efforts to set it up. It can handle the following things but not limited to:
daily seasonality,
holiday effects
input regressors
Lets take a look at a simple example:
We can also trend and the seasonality plots as below:
And finally, we can also see the predictions along with all the confidence intervals
Github: https://github.com/facebook/prophet
Documentation: https://facebook.github.io/prophet/
4. darts:
Darts is another Python package that helps in the manipulation and forecasting of time series. The syntax is “sklearn-friendly” using fit and predict functions to achieve your goals. In addition, it contains a variety of models from ARIMA to Neural Networks.
The best part of the package is that it supports not only univariate but also supports multivariate time series and models. The library also makes it easy to backtest models and combine the predictions of several models and external regressors. Lets take a simple example and understand its working:
Github: https://github.com/unit8co/darts
Documentation: https://unit8co.github.io/darts/README.html
5. AtsPy:
AtsPy stands for Automated Time Series Models in Python. The goal of the library is to forecast univariate time series. You can load the data and specify which models you would like to run as shown in the example below:
The package provides a diverse set of models totally automated. Below is the screenshot of the models available:
Github: https://github.com/firmai/atspy
6. kats:
Kats is another recent library developed by the research team at Facebook dedicated especially to handle time-series data. The goal of the framework is to provide a complete solution for solving time series problems. Using this library we can do the following:
time-series analysis
detection of patterns including seasonalities, outlier, trend changes
feature engineering module that produces 65 features
building forecasting models on time series data including Prophet, ARIMA, Holt-Winters, etc.
The library seems to be promising and it has just released its first version. Some tutorials can be found here.
Github: https://github.com/facebookresearch/Kats
Sktime library as the name suggests is a unified python library that works for time series data and is scikit-learn compatible. It has models for time series forecasting, regression, and classification. The main goal to develop was to interoperate with scikit-learn.
It can do several things but to mention few of them:
State of the art models
Ability to use sklearn’s Pipeline
Model tuning
Ensembling of models
The roadmap of sktime looks very promising and has a lot of developments coming down the pipeline:
Multivariate/panel forecasting,Time series clustering,Time series annotation (segmentation and anomaly detection),Probabilistic time series modeling, including survival and point processes.
Multivariate/panel forecasting,
Time series clustering,
Time series annotation (segmentation and anomaly detection),
Probabilistic time series modeling, including survival and point processes.
If there is a specific library/package you would like me to make a detailed tutorial please do comment and let me know. Also, if there are any other wonderful time series packages that can be added to this list, please do not hesitate to comment. Thank you for your time for reading!
My other articles related to Time-Series:
https://towardsdatascience.com/7-statistical-tests-to-validate-and-help-to-fit-arima-model-33c5853e2e93https://towardsdatascience.com/20-simple-yet-powerful-features-for-time-series-using-date-and-time-af9da649e5dc
https://towardsdatascience.com/7-statistical-tests-to-validate-and-help-to-fit-arima-model-33c5853e2e93
https://towardsdatascience.com/20-simple-yet-powerful-features-for-time-series-using-date-and-time-af9da649e5dc
Follow me on Twitter or LinkedIn. You may also reach out to me via pratikkgandhi@gmail.com
Please sign up for a membership if you want to become a Medium member and enjoy reading articles without any limits. Medium will share a portion with me for any members who sign up using the above link! Thanks.