<jupyter_start><jupyter_text>TIME-SERIES DECOMPOSITION**File:** Decomposition.ipynb**Course:** Data Science Foundations: Data Mining in Python  IMPORT LIBRARIES<jupyter_code>import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.dates import DateFormatter
from statsmodels.tsa.seasonal import seasonal_decompose<jupyter_output><empty_output><jupyter_text>LOAD AND PREPARE DATA<jupyter_code>df = pd.read_csv('data/AirPassengers.csv', parse_dates=['Month'], index_col=['Month'])<jupyter_output><empty_output><jupyter_text>PLOT DATA<jupyter_code>fig, ax = plt.subplots()
plt.xlabel('Year: 1949-1960')
plt.ylabel('Monthly Passengers (1000s)')
plt.title('Monthly Intl Air Passengers')
plt.plot(df, color='black')
ax.xaxis.set_major_formatter(DateFormatter('%Y'))<jupyter_output><empty_output><jupyter_text>DECOMPOSE TIME SERIES - Decompose the time series into three components: trend, seasonal, and residuals or noise.- This commands also plots the components. - The argument `period` specifies that there are 12 observations (i.e., months) in the cycle.- By default, `seasonal_decompose` performs an additive (as opposed to multiplicative) decomposition.<jupyter_code># Set the figure size
plt.rcParams['figure.figsize'] = [7, 8]

# Plot the decomposition components
sd = seasonal_decompose(df, period=12).plot()<jupyter_output><empty_output><jupyter_text>- For growth over time, it may be more appropriate to use a multiplicative trend.- The approach can show consistent changes by percentage.- In this approach, the residuals should be centered on 1 instead of 0.<jupyter_code>sd = seasonal_decompose(df, model='multiplicative').plot()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10523221634332745, 'fraction_numerical': 0.011757789535567314, 'mean_word_length': 7.6395939086294415, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '1947', 'license': 'Apache-2.0', 'n_tokens_mistral': 566, 'n_tokens_neox': 524, 'n_words': 151, 'path': 'Decomposition.ipynb', 'repo_name': 'VladimirsHisamutdinovs/data-mining', 'size': '1701'}