<jupyter_start><jupyter_text>Relationships in Data pt.2  Variance How far a set of numbers is spread out from their average value<jupyter_code>import numpy as np
data = np.array([1, 3, 5, 2, 3, 7, 8, 4, 10, 0, 6, 7, 3, 0, 3, 0, 5, 7, 10, 1, 4, 9, 3])

# first we have a function to calculate the mean
def mean(data):
    return sum(data) / len(data)

def variance(data):
    m = mean(data)
    S = 0
    for xi in data:
        S += (xi - m) #TODO: what needs to be added here?
    return S / (len(data) - 1)

print(variance(data))

#To check your work you can use the built in numpy variance method (np.var())
print(np.var(data, ddof=1))<jupyter_output>0
9.885375494071146<jupyter_text>Application<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

# Running Distance in Mile
X = np.array([3.3,4.4,5.5,6.71,6.93,4.168,9.779,6.182,7.59,2.167,
                         7.042,10.791,5.313,7.997,5.654,9.27,3.1])

# Water Drinks in Litre
Y = np.array([1.7,2.76,2.09,3.19,1.694,1.573,3.366,2.596,2.53,1.221,
                         2.827,3.465,1.65,2.904,2.42,2.94,1.3])

plt.scatter(X, Y)
plt.xlabel('Running Distance (Mile)')
plt.ylabel('Water Drinks (Litre)')

predicted_y_values = list(map(lambda x: 0.7*x + 0.3, X))
plt.scatter(X, Y)
plt.plot(X, predicted_y_values, 'ro-')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1638846737481032, 'fraction_numerical': 0.1244309559939302, 'mean_word_length': 3.441077441077441, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '420286', 'license': 'MIT', 'n_tokens_mistral': 659, 'n_tokens_neox': 565, 'n_words': 141, 'path': 'Class 3.ipynb', 'repo_name': 'timomak/quantitative-reasoning', 'size': '1318'}