Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Machine Learning for Time-Series with Python

You're reading from   Machine Learning for Time-Series with Python Forecast, predict, and detect anomalies with state-of-the-art machine learning methods

Arrow left icon
Product type Paperback
Published in Oct 2021
Publisher Packt
ISBN-13 9781801819626
Length 370 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ben Auffarth Ben Auffarth
Author Profile Icon Ben Auffarth
Ben Auffarth
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Introduction to Time-Series with Python 2. Time-Series Analysis with Python FREE CHAPTER 3. Preprocessing Time-Series 4. Introduction to Machine Learning for Time-Series 5. Forecasting with Moving Averages and Autoregressive Models 6. Unsupervised Methods for Time-Series 7. Machine Learning Models for Time-Series 8. Online Learning for Time-Series 9. Probabilistic Models for Time-Series 10. Deep Learning for Time-Series 11. Reinforcement Learning for Time-Series 12. Multivariate Forecasting 13. Other Books You May Enjoy
14. Index

Python libraries

There are a few popular libraries for classical time-series modeling in Python, but the most popular by far is statsmodels. The following chart compares the popularity of libraries in terms of the number of stars on GitHub:

forecasting_libraries.png

Figure 5.3: Popularity of Python libraries for classical time-series forecasting

Statsmodels is clearly the most popular among these libraries. I've only chosen to include libraries that are actively maintained and that implement the algorithms directly rather than importing them from other libraries. The SkTime or Darts libraries, for example, offer traditional forecasting models, but they are not implemented there, but in statsmodels.

pmdarima (originally pyramid-arima) contains a parameter search to help fit the best ARIMA model to univariate time-series. Anticipy contains a number of models, such as exponential decay and step models. Arch implements tools for financial econometrics and functionality for Autoregressive Conditional Heteroscedasticity (ARCH).

While not as active as Scikit-Learn and only maintained by a couple of people, statsmodels is the go-to library for traditional statistics and econometrics approaches to time-series, with a much stronger emphasis on parameter estimation and statistical testing than machine learning.

Statsmodels

The statsmodels library can help to estimate statistical models and perform statistical tests. It's built on SciPy and NumPy and has lots of statistical functions and models.

The following table illustrates some of the modeling classes relevant to this chapter:

Class

Description

ar_model.AutoReg

Univariate Autoregression Model

arima.model.ARIMA

Autoregressive Integrated Moving Average (ARIMA) model

ExponentialSmoothing

Holt Winter's Exponential Smoothing

SimpleExpSmoothing

Simple Exponential Smoothing

Figure 5.4: A few models implemented in statsmodels

The ARIMA class also has functionality for SARIMA through a seasonal_order parameter, ARIMA, with seasonal components. By definition, ARIMA also supports MA, AR, and differencing (integration).

There are some other models, such as MarkovAutoregression, but we won't go through all of these – we will work through a selection.

Some other useful functions are listed here:

Function

Description

stattools.kpss

Kwiatkowski-Phillips-Schmidt-Shin test for stationarity

stattools.adfuller

Augmented Dickey-Fuller unit root test

stattools.ccf

The cross-correlation function

stattools.pacf

Partial autocorrelation estimate

stats.diagnostic.het_arch

Engle's Test for Autoregressive Conditional Heteroscedasticity (ARCH), also referred to as the ARCH-LM test

stattools.q_stat

Ljung-Box Q Statistic

tsa.seasonal.seasonal_decompose

Seasonal decomposition using moving averages

tsa.tsatools.detrend

Detrend a vector

Figure 5.5: Useful functions in statsmodels

As a convention, we import statsmodels like this:

import statsmodels.api as sm

These statsmodels algorithms are also available through SkTime, which makes them available through an interface similar to the Sklearn interface.

This should be enough for a brief overview. Let's get into the modeling itself!

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Visually different images