MITB Banner

Hands-On Guide To AutoTS: Effective Model Selection for Multiple Time Series

AutoTS allows you to run your data through different models for time series prediction which are already present in it.

Share

AutoTS Banner

Time series data is a type of data that changes over a time period. The sales data of a company does not remain the same for every year, sometimes it’s higher than the previous year, and sometimes it’s lower. Similarly, we see that stock prices are always changing.

Time series prediction is predicting future data with respect to the historic data. Python has different models and libraries which can be used for prediction but we should know which library or model works best for which type of data. Because there are a large number of models but all work on different types of data.

AutoTS allows you to run your data through different models for time series prediction which are already present in it and give out the result for the best model that works for your data. It has around 20 built-in models which make it powerful enough to work on any type of time-series data.

Some of the features of AutoTS are:

  • Around 20 pre-defined models like ARIMA, ETS, VECM etc. are available to use with thousands of possible hyperparameters.
  • It works on finding the best model according to the seasonality and trend of the data by genetic programming
  • AutoTS can handle both Univariate and Multi-Variate Datasets.
  • AutoTS itself clears the data from any NaN columns or outliers which are present.

In this article, we will explore how to use AutoTS to predict time-series data and forecast future data accordingly.

Implementation:

Like any other python library, we will install AutoTS using pip install autots.

  1. Importing Required Libraries

We will use pandas for loading the dataset we will use and Autots for predicting the best model for forecasting of data.

import pandas as pd

from autots import AutoTS

  1. Loading the dataset

I have downloaded the stock data of a stock name Biocon from Yahoo Finance in the csv format which I will use here. The dataset contains different attributes of stock data but we are mainly concerned with Date and Closing price.

df = pd.read_csv('biocon.csv')

df

Dataset
  1. Creating the Model

For calling the model with our dataset we first need to define the model and pass the parameters according to our requirements. While creating the model we will give below parameters:

  • forecast_length
  • frequency
  • ensemble
  • Drop data

#Creating the Model

mod = AutoTS(forecast_length=3, frequency='infer',  ensemble='simple', drop_data_older_than_periods=200 )

  1. Fitting The Model

After creating our model the step is to fit the model according to our dataset. We will also print the name of the model which best works for our data. This step will take some time as it will run our data through different models and check the best model for our data. I won’t be able to show the output of the whole process so I will only print the name of the best Model. 

mod = mod.fit(df, date_col='Date', value_col='Close', id_col=None)

# Name of the best model

print(mod)

Best Model

Here we can see that the best model for our dataset is VECM(Vector Error Correction Model), now we use this model for prediction and forecasting.

  1. Prediction and Forecasting

We can use AutoTS forecast and predict function for this step. As we have selected forecast length as 3 so it will display the forecast of the next 3 days. 

prediction = mod.predict()

forecast = prediction.forecast

model_results = model.results()

validation = model.results("validation")

Let’s print the forecast of the dataset for the future stock price. Also, we will see the validation of the model results. 

#Forecast

print(forecast)

Forecast

#Validation Results

print(validation)

Validation Result

The validation result also contains different attributes i.e errors, weighted errors, etc.  The score of the respective models is also present in the validation results which is used to select the best model.

This is how we can create a model using AutoTS for time series analysis, prediction and forecasting. We can select the model to use by passing a model list and naming the models we want in that list, which will run your data through those models only.

Conclusion:  

In this article, we saw how easily we can use AutoTS to analyze predict and forecast time series data. AutoTs is fast and time-saving because you don’t have to define models explicitly as more than 20 models are already defined in it and the list is ever increasing.

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.