0% found this document useful (0 votes)
11 views10 pages

DEV Ex 5

AD3301 lab manual 5th

Uploaded by

953623243008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views10 pages

DEV Ex 5

AD3301 lab manual 5th

Uploaded by

953623243008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

5.

Perform Time Series Analysis and apply the


various visualization techniques

Aim:
To perform Time Series Analysis and apply the various visualization
techniques.

Code:

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from statsmodels.tsa.seasonal import seasonal_decompose
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
import numpy as np

file_path = r"C:\Users\23ad003\Downloads\archive (1)\


DailyDelhiClimateTest.csv"

data = pd.read_csv(file_path, parse_dates=['date'], index_col='date')


data.head()
Step-by-Step Analysis on this Dataset

1. Basic Line Plot

# Plotting the temperature as an example (you can replace with any other column)
plt.figure(figsize=(10, 6))
plt.plot(data['meantemp'], label='Mean Temperature')
plt.title('Line Plot of Mean Temperature in Delhi')
plt.xlabel('Date')
plt.ylabel('Temperature (°C)')
plt.legend()
plt.show()
2. Decomposition (Trend, Seasonality, and Residuals)
result = seasonal_decompose(data['meantemp'], model='additive', period=30)
result.plot()
plt.show()
3. Moving Average Smoothing
result = seasonal_decompose(data['meantemp'], model='additive', period=30)
result.plot()
plt.show()
4. Autocorrelation and Partial Autocorrelation Plots (ACF & PACF)

plt.figure(figsize=(12, 6))
plot_acf(data['meantemp'].dropna(), lags=40)
plt.show()

plt.figure(figsize=(12, 6))
plot_pacf(data['meantemp'].dropna(), lags=40)
plt.show()
5. Heatmap for Seasonality

data['Month'] = data.index.month
data['Year'] = data.index.year
heatmap_data = data.pivot_table(index='Month', columns='Year',
values='meantemp', aggfunc='mean')

plt.figure(figsize=(10, 6))
sns.heatmap(heatmap_data, cmap="YlGnBu", annot=True)
plt.title('Heatmap Showing Monthly Mean Temperature Across Years')
plt.show()
6. Lag Plot

from pandas.plotting import lag_plot

lag_plot(data['meantemp'])
plt.title('Lag Plot of Mean Temperature')
plt.show()
7. Fourier Transform for Frequency Domain Analysis

fft_values = np.fft.fft(data['meantemp'].dropna())
fft_freq = np.fft.fftfreq(len(data['meantemp'].dropna()))

plt.figure(figsize=(10, 6))
plt.plot(fft_freq, np.abs(fft_values))
plt.title('Fourier Transform - Frequency Spectrum of Mean Temperature')
plt.xlabel('Frequency')
plt.ylabel('Amplitude')
plt.show()
8. Box Plot for Seasonality Trends

plt.figure(figsize=(10, 6))
sns.boxplot(x='Month', y='meantemp', data=data)
plt.title('Box Plot of Monthly Mean Temperature')
plt.show()

Result:
The above program has been run successfully.

You might also like