How to evaluate time series models using AIC in R

This recipe helps you evaluate time series models using AIC in R

Recipe Objective

How to evaluate time series models using AIC.

Time series is a statistical technique that deals with time series data or trend analysis. The AIC: Akaike Information Criteria is an estimator of prediction error which measures a statistical model in order to quantify the goodness of fit of the model. While comparing two models, the smaller the AIC value, the better the time series model. This recipe demonstrates an example of how to evaluate time series models using AIC.

Get Access to Plant Species Identification Project using Machine Learning

Step 1 - Install required package

install.packages('forecast') library(forecast)

Step 2 - Generate random time series data

# Get the data points in form of a R vector. rain <- c(987,1025,978,774,1563,569,1456,789,1479,566,1563,1698) # Convert it to a time series object. rain_ts <- ts(rain,start = c(2020,1),frequency = 12) # Print the timeseries data. print(rain_ts) plot(rain_ts, main = "Time series data") summary(rain_ts)

Step 3 - Build a model using arima()

model1 <- arima(rain_ts, order = c(1,0,0)) model1 model2 <- arima(rain_ts, order = c(2,0,0)) model2

We can try to fit different 'AR models' by changing the order/ The lower the aic term , the better the model. Hence we choose the a model with order - (1,0,0)

Step 4 - Calculate the AIC values

AIC(model) AIC(model2)

Clearly the model1 with arima parameters (1,0,0) is better then model2 as the AIC value of model 1 (179.4) is lesser then AIC of model 2 (181.2)

{"mode":"full","isActive":false}

What Users are saying..

profile image

Ed Godalle

Director Data Analytics at EY / EY Tech
linkedin profile url

I am the Director of Data Analytics with over 10+ years of IT experience. I have a background in SQL, Python, and Big Data working with Accenture, IBM, and Infosys. I am looking to enhance my skills... Read More

Relevant Projects

Build Regression Models in Python for House Price Prediction
In this Machine Learning Regression project, you will build and evaluate various regression models in Python for house price prediction.

Llama2 Project for MetaData Generation using FAISS and RAGs
In this LLM Llama2 Project, you will automate metadata generation using Llama2, RAGs, and AWS to reduce manual efforts.

Learn to Build a Neural network from Scratch using NumPy
In this deep learning project, you will learn to build a neural network from scratch using NumPy

Build a Logistic Regression Model in Python from Scratch
Regression project to implement logistic regression in python from scratch on streaming app data.

Build a Graph Based Recommendation System in Python-Part 2
In this Graph Based Recommender System Project, you will build a recommender system project for eCommerce platforms and learn to use FAISS for efficient similarity search.

Build Customer Propensity to Purchase Model in Python
In this machine learning project, you will learn to build a machine learning model to estimate customer propensity to purchase.

MLOps Project to Build Search Relevancy Algorithm with SBERT
In this MLOps SBERT project you will learn to build and deploy an accurate and scalable search algorithm on AWS using SBERT and ANNOY to enhance search relevancy in news articles.

MLOps using Azure Devops to Deploy a Classification Model
In this MLOps Azure project, you will learn how to deploy a classification machine learning model to predict the customer's license status on Azure through scalable CI/CD ML pipelines.

Locality Sensitive Hashing Python Code for Look-Alike Modelling
In this deep learning project, you will find similar images (lookalikes) using deep learning and locality sensitive hashing to find customers who are most likely to click on an ad.

Build ARCH and GARCH Models in Time Series using Python
In this Project we will build an ARCH and a GARCH model using Python