<jupyter_start><jupyter_text>smoothing.py<jupyter_code>%%runwrite ../timegym/smoothing.py

import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.normal(size=1000), columns=['target'], 
                  index=pd.date_range('2012-12-12', periods=1000))
df<jupyter_output><empty_output><jupyter_text>Moving Averages<jupyter_code>%%runwrite -a ../timegym/smoothing.py

def simple_moving_average(df, window_length=30, min_periods=1):
    df = pd.DataFrame(df)
    ma = df.iloc[:,0].rolling(window_length, min_periods=min_periods).mean()
    ma.rename(f'{df.columns[0]}_MA{window_length}', inplace=True)
    return pd.concat([df, ma], axis=1)
simple_moving_average(df)
%%runwrite -a ../timegym/smoothing.py

def exponential_moving_average(df, exponential_alpha=None, statistic='mean'):
    df = df.copy()
    df = df.ewm(alpha=exponential_alpha)
    if statistic=='mean':
        return df.mean()
    elif statistic=='median':
        return df.median()
    else:
        raise NotImplementedError()
exponential_moving_average(df, exponential_alpha=0.5)<jupyter_output><empty_output><jupyter_text>Kalman Filter<jupyter_code># TODO: implement https://pykalman.github.io/<jupyter_output><empty_output><jupyter_text>Gaussian Processes Smoothing<jupyter_code># TODO: implement https://docs.pymc.io/pymc-examples/examples/gaussian_processes/GP-smoothing.html<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14162473040977713, 'fraction_numerical': 0.017253774263120056, 'mean_word_length': 5.72463768115942, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '561020', 'license': 'MIT', 'n_tokens_mistral': 543, 'n_tokens_neox': 497, 'n_words': 68, 'path': 'dev/2. Smoothing.ipynb', 'repo_name': 'diogoseca/timegym', 'size': '1391'}