Now Reading
Hands-On Guide To Atspy For Automating The Time-Series Forecasting

Hands-On Guide To Atspy For Automating The Time-Series Forecasting

Automating Time Series Prediction

Time Series data is a type of data that changes over a period of time and can be represented over a timeline. Data related to stocks, depreciation of machinery, insurance premium, etc. can be considered as Time series data as it tends to change from time to time. Time series is a part of our everyday life. 

Times series forecasting is a process where we try to forecast/predict what will be the future values of the time series data by studying the historical data. There are a number of models that are used to predict the time series data some of them are ARIMA, GARCH, Prophet, etc. All these models have a certain definition and the parameters are different for them. 

Register for our upcoming Masterclass>>

Atspy provides a way of automating the process of Time Series Forecasting and that too in just a single line of code. Atspy contains a variety of Models such as HWAAS, HWAMS, ARIMA, Prophet, etc. which can be used to predict time series data and we can also compare the results of these models.

In this article, we will explore how we can use Atspy for automating time series forecasting and compare different models which are there in Atspy.


We will start by installing atspy using pip install atspy

Looking for a job change? Let us help you.
  1. Importing Required Libraries

We will be loading the data using pandas so we need to import pandas and we will import different functions from atspy as and when required.

import pandas as pd

  1. Loading the dataset

For using atspy we need data that is strictly preprocessed i.e. there should be no missing data and no period should be missed. I have created a fake dataset which contains the closing sales of a company with the respective month. Let us load the dataset and convert it to set the date column as the index. We need to make sure that our data contains only 1 target column as supported by atspy.

import pandas as pd

df = pd.read_csv("atspy.csv")

df.Date = pd.to_datetime(df.Date)     #changing datatype to datetime

df = df.set_index("Date")     #Setting date as index


Dataset Used
  1. Selecting Models to be used

In this step, we will import the AutomatedModel() function and define a list of Models that we will feed our data to with their names. 

from atspy import AutomatedModel

model_list = ["ARIMA", "Prophet"]

mdl = AutomatedModel(df = df , model_list=model_list, forecast_len=25 )

  1. Insample Model and Prediction

Now we will call the forecaste_insample function which returns the forecast on the insample data and the performance.

forecast_in, performance = mdl.forecast_insample()

Model Creation

Here you can see that itself splits the training and testing data, after that it runs all the models we mentioned in the list defined above for training and forecasting. Now let us print the forecasting and the performance.


Prediction using Models, Atspy


Performance Matrix
  1. Outsample Model and Prediction

Similar to insample prediction now we will use outsample prediction which returns the out-of-sample forecasted dataframe.

forecast_out = mdl.forecast_outsample()

Model Creation, Atspy


Model Prediction, Atspy


performance matrix, Atspy

Here we created a model using ARIMA and Prophet. We can use a lot more models that are defined in atspy and compare the performance of these models.


In this article, we saw how easily we can create models using atspy and compare different models. Atspy is simple and creates models in just a single line of code, which is really timesaving and efficient in terms of prediction. We can create different model predictions in a single line by defining the model list. Currently, Atspy supports around 8 to 10-time series prediction models.

What Do You Think?

Join Our Discord Server. Be part of an engaging online community. Join Here.

Subscribe to our Newsletter

Get the latest updates and relevant offers by sharing your email.

Copyright Analytics India Magazine Pvt Ltd

Scroll To Top