<jupyter_start><jupyter_text>Self Correlation, Self Explanation and Self Prediction1. AUTOCORRELATION FUNCTION    * Helps to identify possible structures of time series data    * Gives a sense of how different points in time relate to each other in away explained by temporal distance    * Note: looking for autocorrelation for irregular time series(17, 21, 30), it does not make sense2. PARTIAL AUTOCORRELATION FUNCTION    * Gives the partial correlation of time series with its own lagged values, controlling for the values of time series at all shorter lags    * Why would this be useful?<jupyter_code>%matplotlib inline
import matplotlib.pylab

%pylab inline
pylab.rcParams['figure.figsize'] = (10,6)

import numpy as np
import pandas as pd
from statsmodels.tsa import stattools
f = pd.read_csv('data/yahoo_stock.csv')<jupyter_output><empty_output><jupyter_text>Time series relate to themselves...First, lets look at the auto correlation function Let's start with white noise<jupyter_code>grid = np.linspace(0,720,500)
noise = np.random.rand(500)
result_curve = noise
plt.plot(grid,result_curve)
acf_result = stattools.acf(result_curve)
plt.plot(acf_result)
plt.axhline(y=0,linestyle='--')
plt.axhline(y=-1.96/np.sqrt(len(result_curve)),linestyle='--')
plt.axhline(y=1.96/np.sqrt(len(result_curve)),linestyle='--')<jupyter_output><empty_output><jupyter_text>How about a periodic function?<jupyter_code>grid = np.linspace(0,100,100)
sin5 = np.sin(grid)
result_curve = sin5
#plt.plot(grid,result_curve)

acf_result = stattools.acf(result_curve,nlags=100)
plt.plot(acf_result)
plt.axhline(y=0,linestyle='--')
plt.axhline(y=-1.96/np.sqrt(len(result_curve)),linestyle='--')
plt.axhline(y=1.96/np.sqrt(len(result_curve)),linestyle='--')<jupyter_output><empty_output><jupyter_text>Now let's look at a real example<jupyter_code>f.head()
plt.plot(f['Open'])
acf_result = stattools.acf(f['Open'],nlags=1000)
plt.subplot(121)
plt.plot(acf_result)
plt.axhline(y=0,linestyle='--')
plt.axhline(y=-1.96/np.sqrt(len(result_curve)),linestyle='--')
plt.axhline(y=1.96/np.sqrt(len(result_curve)),linestyle='--')<jupyter_output><empty_output><jupyter_text>This is not useful as there is a high treand in the data<jupyter_code>diff_f = f['Open'] - f['Open'].shift()
diff_f.plot()
diff_f.dropna(inplace=True)
acf_result = stattools.acf(diff_f)
plt.subplot(121)
plt.plot(acf_result)
plt.axhline(y=0,linestyle='--')
plt.axhline(y=-1.96/np.sqrt(len(result_curve)),linestyle='--')
plt.axhline(y=1.96/np.sqrt(len(result_curve)),linestyle='--')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14549019607843136, 'fraction_numerical': 0.02784313725490196, 'mean_word_length': 6.947040498442368, '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': '565060', 'license': 'Apache-2.0', 'n_tokens_mistral': 1009, 'n_tokens_neox': 936, 'n_words': 185, 'path': 'timeseries/08. Self Correlation.ipynb', 'repo_name': 'vkgpt11/pythonprojects', 'size': '2550'}