Example: Univariate forecast¶
This example shows how to use ATOM to work with a univariate time series dataset.
Import the airline dataset from sktime.datasets. This is a small and easy to train dataset that measures monthly totals of international airline passengers from 1949 to 1960.
Load the data¶
InĀ [1]:
Copied!
# Import packages
import numpy as np
from sktime.datasets import load_airline
from atom import ATOMForecaster
# Import packages
import numpy as np
from sktime.datasets import load_airline
from atom import ATOMForecaster
InĀ [2]:
Copied!
# Load the data
y = load_airline()
print(y)
# Load the data
y = load_airline()
print(y)
Period 1949-01 112.0 1949-02 118.0 1949-03 132.0 1949-04 129.0 1949-05 121.0 ... 1960-08 606.0 1960-09 508.0 1960-10 461.0 1960-11 390.0 1960-12 432.0 Freq: M, Name: Number of airline passengers, Length: 144, dtype: float64
Analyze the data¶
InĀ [3]:
Copied!
atom = ATOMForecaster(y, verbose=2, random_state=1)
atom = ATOMForecaster(y, verbose=2, random_state=1)
<< ================== ATOM ================== >> Configuration ==================== >> Algorithm task: Univariate forecast. Dataset stats ==================== >> Shape: (144, 1) Train set size: 116 --> From: 1949-01 To: 1958-08 Test set size: 28 --> From: 1958-09 To: 1960-12 ------------------------------------- Memory: 6.47 kB Duplicates: 26 (18.1%)
InĀ [4]:
Copied!
# Since the dataset contains only the target column, atom.X is empty
atom.X
# Since the dataset contains only the target column, atom.X is empty
atom.X
Out[4]:
Period |
---|
1949-01 |
1949-02 |
1949-03 |
1949-04 |
1949-05 |
... |
1960-08 |
1960-09 |
1960-10 |
1960-11 |
1960-12 |
144 rows Ć 0 columns
InĀ [5]:
Copied!
# Examine the dataset
atom.plot_series()
# Examine the dataset
atom.plot_series()
InĀ [6]:
Copied!
atom.plot_qq()
atom.plot_qq()
Seasonality¶
InĀ [7]:
Copied!
# ATOM has a number of plots to understand the seasonality of the data
with atom.canvas(rows=2, cols=1, sharex=True, vspace=0.01, legend=None):
atom.plot_acf()
atom.plot_pacf()
# ATOM has a number of plots to understand the seasonality of the data
with atom.canvas(rows=2, cols=1, sharex=True, vspace=0.01, legend=None):
atom.plot_acf()
atom.plot_pacf()
InĀ [8]:
Copied!
with atom.canvas(rows=2, cols=1, sharex=True, vspace=0.01, legend=None):
atom.plot_periodogram()
atom.plot_fft()
with atom.canvas(rows=2, cols=1, sharex=True, vspace=0.01, legend=None):
atom.plot_periodogram()
atom.plot_fft()
InĀ [9]:
Copied!
# It's also possible to compute the seasonality
sp = atom.get_seasonal_period()
sp
# It's also possible to compute the seasonality
sp = atom.get_seasonal_period()
sp
Out[9]:
[12, 24, 36, 11, 48]
InĀ [10]:
Copied!
# And use that seasonality
atom.sp = sp
# And use that seasonality
atom.sp = sp
Run the pipeline¶
InĀ [11]:
Copied!
# Use the regular data cleaning methods to transform the target column
atom.scale(columns=-1)
# Use the regular data cleaning methods to transform the target column
atom.scale(columns=-1)
Fitting Scaler... Scaling features...
InĀ [12]:
Copied!
atom.y
atom.y
Out[12]:
Period 1949-01 -1.388211 1949-02 -1.324254 1949-03 -1.175021 1949-04 -1.207000 1949-05 -1.292275 ... 1960-08 3.877562 1960-09 2.832935 1960-10 2.331940 1960-11 1.575119 1960-12 2.022816 Freq: M, Name: Number of airline passengers, Length: 144, dtype: float64
InĀ [13]:
Copied!
atom.run(["AutoARIMA", "TBATS", "Prophet"])
atom.run(["AutoARIMA", "TBATS", "Prophet"])
Training ========================= >> Models: AutoARIMA, TBATS, Prophet Metric: mape Results for AutoARIMA: Fit --------------------------------------------- Train evaluation --> mape: -1.2991 Test evaluation --> mape: -0.1214 Time elapsed: 3.857s ------------------------------------------------- Time: 3.857s Results for TBATS: Fit --------------------------------------------- Train evaluation --> mape: -1.1261 Test evaluation --> mape: -0.3558 Time elapsed: 37.379s ------------------------------------------------- Time: 37.379s Results for Prophet: Fit --------------------------------------------- Train evaluation --> mape: -1.0705 Test evaluation --> mape: -0.2015 Time elapsed: 0.328s ------------------------------------------------- Time: 0.328s Final results ==================== >> Total time: 41.570s ------------------------------------- AutoARIMA --> mape: -0.1214 ! TBATS --> mape: -0.3558 Prophet --> mape: -0.2015
InĀ [14]:
Copied!
# It's also possible to use regression models for forecast tasks
atom.run("RF")
# It's also possible to use regression models for forecast tasks
atom.run("RF")
Training ========================= >> Models: RF Metric: mape Results for RandomForest: Fit --------------------------------------------- Train evaluation --> mape: nan Test evaluation --> mape: -0.4553 Time elapsed: 0.220s ------------------------------------------------- Time: 0.220s Final results ==================== >> Total time: 0.222s ------------------------------------- RandomForest --> mape: -0.4553
InĀ [15]:
Copied!
atom.rf.estimator
atom.rf.estimator
Out[15]:
RecursiveTabularRegressionForecaster(estimator=RandomForestRegressor())Please rerun this cell to show the HTML repr or trust the notebook.
RecursiveTabularRegressionForecaster(estimator=RandomForestRegressor())
RandomForestRegressor()
Analyze the results¶
InĀ [16]:
Copied!
atom.evaluate()
atom.evaluate()
Out[16]:
Ā | mae | mape | mse | r2 | rmse |
---|---|---|---|---|---|
AutoARIMA | -0.209400 | -0.121400 | -0.062900 | 0.910300 | -0.250700 |
TBATS | -0.555500 | -0.355800 | -0.392200 | 0.440300 | -0.626300 |
Prophet | -0.350100 | -0.201500 | -0.181200 | 0.741500 | -0.425600 |
RF | -0.723300 | -0.455300 | -0.756200 | -0.079100 | -0.869600 |
InĀ [17]:
Copied!
atom.winner.plot_forecast()
atom.winner.plot_forecast()
InĀ [18]:
Copied!
atom.plot_errors()
atom.plot_errors()