Quantification de l'ajustement de la régression logistique

Introduction à la régression avec statsmodels en Python

Maarten Van den Broeck

Content Developer at DataCamp

Les quatre résultats

faux prédit prédit vrai
réel faux correct faux positif
réel vrai faux négatif correct
Introduction à la régression avec statsmodels en Python

Matrice de confusion : nombre de résultats

actual_response = churn["has_churned"]
predicted_response = np.round(mdl_recency.predict())
outcomes = pd.DataFrame({"actual_response": actual_response,
                         "predicted_response": predicted_response})
print(outcomes.value_counts(sort=False))
actual_response  predicted_response
0                0.0                   141
                 1.0                    59
1                0.0                   111
                 1.0                    89
Introduction à la régression avec statsmodels en Python

Visualisation de la matrice de confusion

conf_matrix = mdl_recency.pred_table()

print(conf_matrix)
[[141.              59.]
 [111.              89.]] 
vrai négatif faux positif
faux négatif vrai positif
from statsmodels.graphics.mosaicplot
import mosaic

mosaic(conf_matrix)

Graphique en mosaïque représentant les résultats du modèle d’attrition en comparaison à la récence. Il y a 200 observations pour les clients ayant réellement quitté l'entreprise et 200 pour ceux qui sont restés, chaque colonne a donc la même largeur.

Introduction à la régression avec statsmodels en Python

Précision

La précision est la proportion de prédictions correctes.

$$ \text{accuracy} = \frac{TN + TP}{TN + FN + FP + TP} $$

 [[141.,  59.],
  [111.,  89.]]
TN = conf_matrix[0,0]
TP = conf_matrix[1,1]
FN = conf_matrix[1,0]
FP = conf_matrix[0,1]
acc = (TN + TP) / (TN + TP + FN + FP)
print(acc)
0.575
Introduction à la régression avec statsmodels en Python

Sensibilité

La sensibilité est la proportion de vrais positifs.

$$ \text{sensitivity} = \frac{TP}{FN + TP} $$

 [[141.,  59.],
  [111.,  89.]]
TN = conf_matrix[0,0]
TP = conf_matrix[1,1]
FN = conf_matrix[1,0]
FP = conf_matrix[0,1]
sens = TP / (FN + TP)
print(sens)
0.445
Introduction à la régression avec statsmodels en Python

Spécificité

La spécificité est la proportion de vrais négatifs.

$$ \text{specificity} = \frac{TN}{TN + FP} $$

 [[141.,  59.],
  [111.,  89.]]
TN = conf_matrix[0,0]
TP = conf_matrix[1,1]
FN = conf_matrix[1,0]
FP = conf_matrix[0,1]
spec = TN / (TN + FP)
print(spec)
0.705
Introduction à la régression avec statsmodels en Python

Passons à la pratique !

Introduction à la régression avec statsmodels en Python

Preparing Video For Download...