In [ ]:
import scipy.stats as stats
import matplotlib.pyplot as plt
p_values = []
test_val = []
# Calcola il test di normalità per ciascuna colonna del dataframe
for column in encoded_df.columns:
test = stats.normaltest(encoded_df[column])
p_values.append(test[1])
test_val.append(test[0])
# Crea un dataframe contenente i risultati del test di normalità
norm_df = pd.DataFrame(
{"Feature": encoded_df.columns, "D'Agostino-Pearson": test_val, "P-value": p_values}
)
norm_df.set_index("Feature", inplace=True)
# Definisci una funzione per colorare le celle in base al p-value
def color_cells(val):
color = (
"green" if val >= 0.05 else "red"
) # Assumendo un livello di significatività del 0.05
if val > 1:
color = None
return "background-color: %s" % color
# Applica la funzione di colorazione al DataFrame
styled_norm_df = norm_df.style.applymap(color_cells)
styled_norm_df
Out[ ]:
| D'Agostino-Pearson | P-value | |
|---|---|---|
| Feature | ||
| sepal.length | 5.735584 | 0.056824 |
| sepal.width | 3.123832 | 0.209734 |
| petal.length | 221.687294 | 0.000000 |
| petal.width | 137.555965 | 0.000000 |
| encoded.variety | 1025.484477 | 0.000000 |