Created
May 16, 2012 08:10
-
-
Save sheymann/2708599 to your computer and use it in GitHub Desktop.
Mean, Standard deviation and Skewness functions
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 sys | |
import math | |
myvalues = [-3, -2, -1, -1, 0, 1, 2, 3, 7] | |
def moy(l): | |
sommeval = reduce(lambda somme, val: somme+val, l, 0) | |
return (float(sommeval)/len(l)) | |
def stddev(l): | |
mu = moy(l) | |
n = len(l) | |
cur_est = 0 | |
for x in l: | |
cur_est += (float(x)-mu)*(float(x)-mu) | |
return (float(cur_est)/(n-1)) | |
def skew(l): | |
mu = moy(l) | |
sigma = math.sqrt(stddev(l)) | |
n = len(l) | |
cur_est = 0 | |
for x in l: | |
cur_est += ((float(x)-mu)/sigma)**3 | |
return (cur_est*n)/((n-1)*(n-2)) | |
sys.stdout.write("%f %f\n"%(skew(myvalues), moy(myvalues))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment