MITB Banner

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.

Share

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. 

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.

Implementation:   

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

df.head()

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.

forecast_in

Prediction using Models, Atspy

performance

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

forecast_out

Model Prediction, Atspy

performance

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.

Conclusion:

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.

Share
Picture of Himanshu Sharma

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

CORPORATE TRAINING PROGRAMS ON GENERATIVE AI

Generative AI Skilling for Enterprises

Our customized corporate training program on Generative AI provides a unique opportunity to empower, retain, and advance your talent.

Upcoming Large format Conference

May 30 and 31, 2024 | 📍 Bangalore, India

Download the easiest way to
stay informed

Subscribe to The Belamy: Our Weekly Newsletter

Biggest AI stories, delivered to your inbox every week.

AI Courses & Careers

Become a Certified Generative AI Engineer

AI Forum for India

Our Discord Community for AI Ecosystem, In collaboration with NVIDIA. 

Flagship Events

Rising 2024 | DE&I in Tech Summit

April 4 and 5, 2024 | 📍 Hilton Convention Center, Manyata Tech Park, Bangalore

MachineCon GCC Summit 2024

June 28 2024 | 📍Bangalore, India

MachineCon USA 2024

26 July 2024 | 583 Park Avenue, New York

Cypher India 2024

September 25-27, 2024 | 📍Bangalore, India

Cypher USA 2024

Nov 21-22 2024 | 📍Santa Clara Convention Center, California, USA

Data Engineering Summit 2024

May 30 and 31, 2024 | 📍 Bangalore, India

Subscribe to Our Newsletter

The Belamy, our weekly Newsletter is a rage. Just enter your email below.