Created
May 24, 2019 14:24
-
-
Save eLtronicsVilla/755e494e3f8ed1cdeac65150e6f6f7a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import numpy as np | |
data_input = [5,6,8,12,15,18,10] | |
def mean(x): | |
return sum(x)/len(x) | |
def sum_of_squares(v): | |
"""v_1*v_1 +... +v_n*v_n""" | |
return np.dot(v,v) | |
def dev_mean(data): | |
# convert x by subtracting its mean ( so the result has mean 0) | |
x_bar = mean(data) | |
return [x_i - x_bar for x_i in data] | |
def variance(data): | |
# assumes x has at least two element | |
n = len(data) | |
deviations = dev_mean(data) | |
return sum_of_squares(deviations) / (n-1) | |
print(dev_mean(data_input)) | |
print(variance(data_input)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment