Active Hackathon

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

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.
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. 


Sign up for your weekly dose of what's up in emerging technology.

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

  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.

More Great AIM Stories

Himanshu Sharma
An aspiring Data Scientist currently Pursuing MBA in Applied Data Science, with an Interest in the financial markets. I have experience in Data Analytics, Data Visualization, Machine Learning, Creating Dashboards and Writing articles related to Data Science.

Our Upcoming Events

Conference, Virtual
Genpact Analytics Career Day
3rd Sep

Conference, in-person (Bangalore)
Cypher 2022
21-23rd Sep

Conference, in-person (Bangalore)
Machine Learning Developers Summit (MLDS) 2023
19-20th Jan, 2023

Conference, in-person (Bangalore)
Data Engineering Summit (DES) 2023
21st Apr, 2023

Conference, in-person (Bangalore)
MachineCon 2023
23rd Jun, 2023

3 Ways to Join our Community

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Telegram Channel

Discover special offers, top stories, upcoming events, and more.

Subscribe to our newsletter

Get the latest updates from AIM