How to create Time Series Plots in the StatsModels library?

This recipe describes how to create Time Series Plots in the StatsModels library

Recipe Objective - How to create Time Series Plots in the StatsModels library?

There are four different time series plots available in the StatsModel library.

Build a Chatbot in Python from Scratch! 

For more related projects -

https://www.dezyre.com/projects/data-science-projects/deep-learning-projects
https://www.dezyre.com/projects/data-science-projects/neural-network-projects

Different time series plots:

plot_acf(x[, ax, lags, alpha, use_vlines, ...])
Plot the autocorrelation function

plot_pacf(x[, ax, lags, alpha, method, ...])
Plot the partial autocorrelation function

month_plot(x[, dates, ylabel, ax])
The seasonal plot of monthly data.

quarter_plot(x[, dates, ylabel, ax])
The seasonal plot of quarterly data

Example of month_plot:

# Importing libraries
import statsmodels.api as sm
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)

# Importing elnino dataset in the form of pandas dataframe
data = sm.datasets.elnino.load_pandas().data

# Converting year into proper format
data['YEAR'] = data.YEAR.astype(int).astype(str)
data = data.set_index('YEAR').T.unstack()
datetime = pd.to_datetime(list(map(lambda x: '-'.join(x), data.index.values)))
data.index = pd.DatetimeIndex(datetime, freq='infer')

# Month plot
fig = sm.graphics.tsa.month_plot(data)

In this way, we can create Time Series Plots in the StatsModels library.

What Users are saying..

profile image

Savvy Sahai

Data Science Intern, Capgemini
linkedin profile url

As a student looking to break into the field of data engineering and data science, one can get really confused as to which path to take. Very few ways to do it are Google, YouTube, etc. I was one of... Read More

Relevant Projects

Deploying Machine Learning Models with Flask for Beginners
In this MLOps on GCP project you will learn to deploy a sales forecasting ML Model using Flask.

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 Similar Images Finder with Python, Keras, and Tensorflow
Build your own image similarity application using Python to search and find images of products that are similar to any given product. You will implement the K-Nearest Neighbor algorithm to find products with maximum similarity.

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.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Learn to Build a Polynomial Regression Model from Scratch
In this Machine Learning Regression project, you will learn to build a polynomial regression model to predict points scored by the sports team.

Skip Gram Model Python Implementation for Word Embeddings
Skip-Gram Model word2vec Example -Learn how to implement the skip gram algorithm in NLP for word embeddings on a set of documents.

Build Deep Autoencoders Model for Anomaly Detection in Python
In this deep learning project , you will build and deploy a deep autoencoders model using Flask.

Build a Autoregressive and Moving Average Time Series Model
In this time series project, you will learn to build Autoregressive and Moving Average Time Series Models to forecast future readings, optimize performance, and harness the power of predictive analytics for sensor data.

Deep Learning Project for Time Series Forecasting in Python
Deep Learning for Time Series Forecasting in Python -A Hands-On Approach to Build Deep Learning Models (MLP, CNN, LSTM, and a Hybrid Model CNN-LSTM) on Time Series Data.