<jupyter_start><jupyter_text>Time Series - SklearnA note regarding `time series` implementation using sklearn   Imports<jupyter_code>%matplotlib inline

import os, sys, time, tqdm

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

from sklearn import datasets, linear_model
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_boston
df = pd.read_csv('./dataset/zuerich_monthly_sunspot_numbers.csv')
df = df.iloc[:-1,:]

df['Date'] =  pd.to_datetime(df['Month'])
df = df.drop('Month',axis=1)

df['Year'] = df['Date'].dt.year
df['Month'] = df['Date'].dt.month

df = df.set_index('Date')

df.head(3)
df.describe()
df.loc[:,'Zuerich monthly sunspot numbers 1749-1983'].plot()
df_mm = df.loc[:,'Zuerich monthly sunspot numbers 1749-1983'].resample('A').mean() # resample annually 
df_mm.plot(style='g--')
df_mm = df.loc[:,'Zuerich monthly sunspot numbers 1749-1983'].resample("A").apply(['mean', np.min, np.max])
df_mm['1900':'2020'].plot(subplots=True)
df_mm['1900':'2020'].plot()
from statsmodels.graphics.tsaplots import plot_acf
import matplotlib.dates as mdates

import statsmodels.api as sm

import seaborn as sns
sns.set_style('whitegrid')
sns.set_context('talk')


plot_acf(df.loc[:,'Zuerich monthly sunspot numbers 1749-1983'], lags=31)
plt.show()<jupyter_output><empty_output><jupyter_text>Time Series DecompositionThis is not fully functional at this time, see this SO questionThe frequency of decomposition must be an interval, which 'may' repeat. So we have data with 15min frequency and we are looking for a weekly repetition of behavior.$decompfreq = \cfrac{24h \cdot 60min}{15min} \cdot 7days$<jupyter_code>type(df.loc[0,'Zuerich monthly sunspot numbers 1749-1983'])
type(decompfreq)
type(df.loc[:,'Zuerich monthly sunspot numbers 1749-1983'])
decompfreq = np.float64(24*60/15*7)
res = sm.tsa.seasonal_decompose(df.loc[:,'Zuerich monthly sunspot numbers 1749-1983'].interpolate(),
                                freq=int(decompfreq),
                                model='additive')
with mpl.rc_context():
    mpl.rc("figure", figsize=(30,10))
    resplot = res.plot()
    resplot.savefig('Seasonal_Decompose.png', dpi=150)
?res.plot<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13702882483370288, 'fraction_numerical': 0.04567627494456763, 'mean_word_length': 5.266666666666667, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '506651', 'license': 'MIT', 'n_tokens_mistral': 855, 'n_tokens_neox': 769, 'n_words': 185, 'path': 'Simple Timeseries.ipynb', 'repo_name': 'eljirg/Machine-Learning', 'size': '2255'}