40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
|
|
from math import sqrt
|
|
|
|
sandales = {5:3 , 15:16, 25:28, 35:43, 45:47, 50:60, 65:24, 75:15, 85:10, 95:7, 105:1, 135:2}
|
|
appPhotos = {20:5, 60:7, 100:10, 140:17, 180:9, 220:3, 260:12, 300:3, 380:2, 420:4}
|
|
|
|
def mean(dict):
|
|
somme = sum([i*dict[i] for i in dict.keys()])
|
|
effectif = sum(dict.values())
|
|
return float(somme)/effectif
|
|
|
|
def sd(dict):
|
|
m = mean(dict)
|
|
somme = sum([(i-m)**2*dict[i] for i in dict.keys()])
|
|
effectif = sum(dict.values())
|
|
return sqrt(float(somme)/effectif)
|
|
|
|
def analyse(dict):
|
|
m = mean(dict)
|
|
et = sd(dict)
|
|
lowB = m - et
|
|
highB = m + et
|
|
inConfiance1 = [dict[i] for i in dict.keys() if (i <= highB) and (i >= lowB)]
|
|
somme1 = sum(inConfiance1)
|
|
lowB = m - 2*et
|
|
highB = m + 2*et
|
|
inConfiance2 = [dict[i] for i in dict.keys() if (i <= highB) and (i >= lowB)]
|
|
somme2 = sum(inConfiance2)
|
|
effectif = sum(dict.values())
|
|
print("mean : {m} \n sd = {et}".format(m = m , et = et))
|
|
print("[{l} ; {h}] -> {val}".format(l = lowB , h = highB , val = str(inConfiance1)))
|
|
print("Pourcentage: {pourc}%".format(pourc = 100*somme1 / effectif))
|
|
print("[{l} ; {h}] -> {val}".format(l = lowB , h = highB , val = str(inConfiance2)))
|
|
print("Pourcentage: {pourc}%".format(pourc = 100*somme2 / effectif))
|
|
|
|
|
|
analyse(sandales)
|
|
analyse(appPhotos)
|
|
|