TIME SERIES ANALYSIS IN PYTHON 😎

Sampath Kumaran Ganesan
2 min readMar 24, 2023

--

Time series analysis using statistical analysis techniques, LSTM and Time series transformers

So, What is Time Series??

Time series is a collection of data points or observations obtained through repeated measurements over time. Simply put, it is a series of data points indexed over time. It can also be said as data that is recorded over continuous intervals of time.

Example: Sales forecasting, Temperature reading, Rainfall measurements, Heart rate monitoring (ECG), Brain signal monitoring (EEG), Stock trading etc.,

Difference between regression and time series analysis

In regression, we make an assumption of all features are independent of each other. But in time series analysis, feature is dependent on the time factor. In time series forecasting, we are generally interested in predicting something that will change over time. For Example, you may have a data set of building prices with features describing the building including the year that building was built. Even though you have a date as a feature, this is not a time series problem.

Terminologies in Time Series

Synthetic Data is used. It is from package called β€œstatsmodels”

TREND: Long term movement of time series. Trend is observed when there is an increasing or decreasing slope in the time series.

SEASONALITY: Seasonality discovers variations that occur at constant intervals of time. Examples include seasons and festivals. The variations occur during the same period over and over again and hence affect how we predict data.

STATIONARY: Time series having same set of properties even after the duration of time.

import numpy as np
import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt

data = sm.datasets.co2.load_pandas().data

fig, ax = plt.subplots(figsize=(16, 11))
ax.plot(data['co2'])
ax.set_xlabel('Time')
ax.set_ylabel('CO2 concentration (ppmw)')
fig.autofmt_xdate()
plt.tight_layout()

Below is the output for this code:

Weekly CO2 concentration (ppmv) from 1958 to 2001

From the above output, we could see there is a positive trend when moving towards future i.e., from 1960 to 2000. We could also observe a yearly seasonal pattern. This is due to the change of seasons.

Next, We will continue developing time series analysis using ARIMA, LSTM and TRANSFORMER

--

--

No responses yet