Skip to content

Instantly share code, notes, and snippets.

@tmiz
Created June 26, 2014 14:09
Show Gist options
  • Save tmiz/f575a7ec737be2dc2b97 to your computer and use it in GitHub Desktop.
Save tmiz/f575a7ec737be2dc2b97 to your computer and use it in GitHub Desktop.
Mean And Stddev
import math
class MeanAndStddev:
def __init__(self):
self.values = [];
def append(self, val):
self.values.append(val * 1.0)
def mean(self):
sumValue = 0
for a in self.values:
sumValue += a
return sumValue/len(self.values)
def variance(self):
mean = self.mean()
sumMean = 0.0
for a in self.values:
sumMean += (a - mean) * (a - mean)
return sumMean / len(self.values)
def stddev(self):
return math.sqrt(self.variance())
def standardScore(self, index):
return ((10.0 * (self.values[index] - self.mean()))/ self.stddev()) + 50.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment