1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
import numpy as np
import math as math
data = np.loadtxt('etude.csv', delimiter=';', skiprows=1)
longueur = len(data)
max = max(data)
min = min(data)
moyenne = np.mean(data)
ecart_type = np.std(data)
quart1 = np.percentile(data, 25)
quart3 = np.percentile(data, 75)
interquartile = quart3 - quart1
nb_classe = None
etendu = max - min
amplitude_egale = []
seuils_observes = []
moyenne_emboitee = []
progr_arith = []
progr_geom = []
standardisation = []
effectifs_egaux = []
Brooks_Carruthers = 5 * math.log10(longueur)
Huntsberger = 1 + 3.332 * math.log10(longueur)
Sturges = math.log(longueur + 1, 2)
Scott = (max - min) / (3.5 * ecart_type * pow(longueur, (-1/3)))
Freedman_Diaconis = (max - min) / (2 * interquartile * pow(longueur, (-1/3)))
print("----------NOMBRE DE CLASSES CONSEILLEES----------\n")
print("Brooks_Carruthers = %s\nHuntsberger = %s\nSturges = %s\nScott = %s\nFreedman_Diaconis = %s" % (round(Brooks_Carruthers,2), round(Huntsberger,2), round(Sturges,2), round(Scott,2), round(Freedman_Diaconis, 2)))
print("\n")
print("Moyenne = %s" % round(((Brooks_Carruthers + Huntsberger + Sturges + Scott + Freedman_Diaconis) / 5), 2))
print("\n\n")
nb_classe = int(input("Combien de classes prends-tu : "))
print("\n\n")
print("------------------------ Indicatif ---------------------------")
print("Nombre d'individus : %s" %longueur)
print("Minimum = %s" %min)
print("Maximum = %s" %max)
print("Moyenne = %s" %round(moyenne, 2))
print("Ecart-type = %s" %round(ecart_type, 2))
print("\n\n")
print("------------------------ Discrétisation en classe d'amplitude égale (vérifié) ---------------------------")
"""IDEAL POUR VALORISER LES VALEURS EXTREMES"""
amplitude_type = etendu / nb_classe
#print("amplitude = %s" %amplitude_type)
#print("etendu = %s" %etendu)
for i in range(0, nb_classe + 1):
donne = min + (amplitude_type * i)
amplitude_egale.append(donne)
for i in range(0, nb_classe):
print("]", round(amplitude_egale[i], 2), ";", round(amplitude_egale[i+1], 2), "]")
print("------------------------ Discrétisation par standardisation (vérifié, attention au max) ---------------------------")
if (nb_classe == 5):
standardisation.append(moyenne - 2.5*ecart_type)
standardisation.append(moyenne - 1.5*ecart_type)
standardisation.append(moyenne - 0.5*ecart_type)
standardisation.append(moyenne + 0.5*ecart_type)
standardisation.append(moyenne + 1.5*ecart_type)
standardisation.append(moyenne + 2.5*ecart_type)
if (nb_classe == 6):
standardisation.append(moyenne - 3*ecart_type)
standardisation.append(moyenne - 2*ecart_type)
standardisation.append(moyenne - 1*ecart_type)
standardisation.append(moyenne)
standardisation.append(moyenne + 1*ecart_type)
standardisation.append(moyenne + 2*ecart_type)
standardisation.append(moyenne + 3*ecart_type)
if (nb_classe == 4):
standardisation.append(moyenne - 2*ecart_type)
standardisation.append(moyenne - 1*ecart_type)
standardisation.append(moyenne)
standardisation.append(moyenne + 1*ecart_type)
standardisation.append(moyenne + 2*ecart_type)
if (nb_classe == 3):
standardisation.append(moyenne - 1.5*ecart_type)
standardisation.append(moyenne - 0.5*ecart_type)
standardisation.append(moyenne + 0.5*ecart_type)
standardisation.append(moyenne + 1.5*ecart_type)
standardisation.sort()
for i in range(0, nb_classe):
print("]", round(standardisation[i], 2), ";", round(standardisation[i+1], 2), "]")
print("------------------------ Discrétisation en progression arithmétique (vérifié) ---------------------------")
raison = (max - min) / (0.5*nb_classe*(nb_classe + 1))
donne = min
for i in range(0, nb_classe + 1):
donne = donne + (raison * i)
progr_arith.append(donne)
for i in range(0, nb_classe):
print("]", round(progr_arith[i], 2), ";", round(progr_arith[i+1], 2), "]")
print("------------------------ Discrétisation en progression géométrique ---------------------------")
raison = pow(10, (math.log10(max) - math.log10(min)) / nb_classe)
for i in range(0, nb_classe + 1):
donne = min * pow(raison, i)
progr_geom.append(donne)
for i in range(0, nb_classe):
print("]", round(progr_geom[i], 2), ";", round(progr_geom[i+1], 2), "]")
print("------------------------ Discrétisation par effectifs égaux (quantiles) (vérifié) ---------------------------")
for i in range(0, nb_classe + 1):
donne = np.percentile(data, (100 / nb_classe) * i)
effectifs_egaux.append(donne)
for i in range(0, nb_classe):
print("]", round(effectifs_egaux[i], 2), ";", round(effectifs_egaux[i+1], 2), "]")
print("------------------------ Discrétisation par moyennes emboitees (bizarre sur l'exemple) ---------------------------")
if (nb_classe == 2) or (nb_classe == 3):
moyenne_emboitee.append(min)
moyenne_emboitee.append(moyenne)
moyenne_emboitee.append(max)
elif (nb_classe == 4) or (nb_classe == 5):
moyenne_emboitee.append(min)
moyenne_emboitee.append((min + moyenne) / 2)
moyenne_emboitee.append(moyenne)
moyenne_emboitee.append((max + moyenne) / 2)
moyenne_emboitee.append(max)
else:
print("NB_CLASS TROP GRAND")
moyenne_emboitee.sort()
print(moyenne_emboitee) |
Partager