<jupyter_start><jupyter_text>SESONAL DECOMPOSITIONThe decomposition procedure is to describe the trend and seasonalityGoal: to estimate the seasonal effects that can be used to create and presnet seasonally adjusted values, thus removing the seasonal effect from a value so that trends can be seen more clearly DECOMPOSITION MODELSThere are 2 decomposition models: 1. Additive:  $x_t = trend + seasonal + random $--> The Additive model is used when seasonal variation is constant over time --> The additive model is linear 2. Multiplicative: $x_t = trend * seasonal * random $--> The Multiplicative model is used when seasonal variation is positive over time (changes increase or decrease over time)--> The multiplicative model is nonlinear<jupyter_code># Load packages
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pandas_datareader.data as web
import statsmodels.api as sm 
from random import randrange
from pandas import Series
from statsmodels.tsa.seasonal import seasonal_decompose

# Read the Airline Passengers dataset
series = pd.read_csv('airline_passengers.csv', header = 0, index_col = 0)
series.plot()
plt.show()<jupyter_output><empty_output><jupyter_text>For above data, we will try the Multiplicative model DECOMPOSITION STEPS STEP 1: ESTIMATE THE TREND VALUESThis step can be done by: 1. moving averages or 2. modeling the trend with regression model  STEP 2:  'DE-TREND' THE SERIES1. For additive model: subtract the trend estimates (from step 1) from the series 2. For multiplicative model: divide the series by the trend value STEP 3: ESTIMATE SEASONAL FACTORS The seasonal factors are estimated using the 'de-trend' series found in step 2. A common way to do it is averaging the de-trend values for a specific season  STEP 4: DETERMINE THE RANDOM (IRREGULAR) COMPONENT<jupyter_code># DECOMPOSE THE 'AIRLINE PASSENTERS' DATASET USING MULTIPLICATIVE MODEL 
series = pd.read_csv('airline_passengers.csv')
series.Month = pd.to_datetime(series.Month, errors = 'coerce')
series = series.set_index('Month')
result = seasonal_decompose(series, model = 'multiplicative')
result.plot()
plt.figure(figsize=(20,10))
print(result.trend[7])
#print(series)
#len(result.trend)<jupyter_output>127.24999999999999
{'fraction_non_alphanumeric': 0.06726057906458797, 'fraction_numerical': 0.01648106904231626, 'mean_word_length': 5.644970414201183, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '341289', 'license': 'MIT', 'n_tokens_mistral': 700, 'n_tokens_neox': 638, 'n_words': 274, 'path': 'seasonal_decomp.ipynb', 'repo_name': 'mh86/timeseries_learning', 'size': '2245'}