<jupyter_start><jupyter_text>Dependencies<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
def demean(a):
  return a - np.mean(a) * np.array([1]*len(a))

def correlation(a,b):
  a,b = demean(a), demean(b)
  return (a@b)/(np.linalg.norm(a)*np.linalg.norm(b))
a = np.sin(np.linspace(0,6,100)) + np.random.uniform(-0.4,0.4,100)
b = np.sin(np.linspace(0,6,100)) + np.random.uniform(-0.4,0.4,100)

print(f'The correlation between a and b is = ', correlation(a,b))
fig, ax = plt.subplots(1,1,figsize=(7,7),dpi=120)
ax.plot(np.linspace(0,6,100), a, label='A series', marker='o', linestyle='dashed')
ax.plot(np.linspace(0,6,100), b, label='b series', marker='o', linestyle='dashed')
ax.legend()
plt.show()
fig, ax = plt.subplots(1,1,figsize=(7,7),dpi=120)
ax.scatter(a,b)
ax.set_xlabel(r'$a_{i}$')
ax.set_ylabel(r'$b_{i}$')
plt.show()
a = np.sin(np.linspace(0,6,100)) + np.random.uniform(-0.4,0.4,100)
b = np.cos(np.linspace(2,7,100)) + np.random.uniform(-0.4,0.4,100)
print(f'The correlation between a and b is = ', correlation(a,b))
fig, ax = plt.subplots(1,1,figsize=(7,7),dpi=120)
ax.plot(np.linspace(0,6,100),a,label='a series',marker='o',linestyle='dashed')
ax.plot(np.linspace(0,6,100),b,label='b series',marker='o',linestyle='dashed')
ax.legend()
plt.show()
fig, ax = plt.subplots(1,1,figsize=(7,7),dpi=120)
ax.scatter(a,b)
ax.set_xlabel(r'$a_{i}$')
ax.set_ylabel(r'$b_{i}$')
plt.show()
a = np.cos(np.linspace(0,6,100)) + np.random.uniform(-0.4,0.4,100)
b = np.exp(np.linspace(0,6,100)) + np.random.uniform(-0.4,0.4,100)
print(f'The correlation between a and b is = ', correlation(a,b))
fig, ax = plt.subplots(1,1,figsize=(7,7),dpi=120)
ax.plot(np.linspace(0,6,100),a,label='a series',marker='o',linestyle='dashed')
ax.plot(np.linspace(0,6,100),b,label='b series',marker='o',linestyle='dashed')
ax.legend()
plt.show()
fig, ax = plt.subplots(1,1,figsize=(7,7),dpi=120)
ax.scatter(a,b)
ax.set_xlabel(r'$a_{i}$')
ax.set_ylabel(r'$b_{i}$')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2466097438473129, 'fraction_numerical': 0.07282772476142642, 'mean_word_length': 7.265560165975104, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '625791', 'license': 'MIT', 'n_tokens_mistral': 988, 'n_tokens_neox': 935, 'n_words': 119, 'path': 'vectors_and_correlation.ipynb', 'repo_name': 'oramirezperera/Vectors_linear_algebra', 'size': '1991'}