<jupyter_start><jupyter_text>Construct sample data<jupyter_code># The number of points in the time series. 
n = 1000

x = np.linspace(-100, 100, 1000)
y = 2 + np.cos(x) + np.random.normal(0, 0.1, 1000)<jupyter_output><empty_output><jupyter_text>Finding a smoothed version of the time series:<jupyter_code># construct a 31-point Gaussian filter with std 4
filt = gaussian(31, 4)
filt /= sum(filt)

# padd data on both side, apply filter
padded = concatenate((y[0]*ones(31//2), y, y[n-1]*ones(31//2)))
smooth = convolve(padded, filt, mode='valid')

# Plot the raw data together with the smoothed data: # 1) Create a figure, sized to 7x5 inches
figure(1, figsize=(7, 5))

# Plot the raw data in red
plot(y[:100], 'r')

# Plot the smoothed data in blue 
plot(smooth[:100], 'b')<jupyter_output><empty_output><jupyter_text>Using Pandas for Simple Moving Average<jupyter_code>import pandas as pd
df = pd.DataFrame({'x' : x, 'y' : y})
df_ma = df.rolling(15).mean()
figure(figsize=(16, 4))
plot(df.x, df.y)
plot(df_ma.x, df_ma.y)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15047619047619049, 'fraction_numerical': 0.05047619047619047, 'mean_word_length': 5.527950310559007, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '443850', 'license': 'MIT', 'n_tokens_mistral': 456, 'n_tokens_neox': 403, 'n_words': 115, 'path': 'preprocessing/smoothing.ipynb', 'repo_name': 'shawlu95/Data_Science_Toolbox', 'size': '1050'}