Created
June 26, 2014 14:09
-
-
Save tmiz/f575a7ec737be2dc2b97 to your computer and use it in GitHub Desktop.
Mean And Stddev
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 | |
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