Construire la table du predictor insight graph
Dans l’exercice précédent, vous avez appris à calculer la colonne d’incidence de la table du predictor insight graph. Dans cet exercice, vous allez aussi ajouter la taille des groupes et regrouper le tout dans une fonction qui renvoie la table du predictor insight graph pour une variable donnée.
Cet exercice fait partie du cours
Introduction à l’analytique prédictive en Python
Instructions
- Regroupez la basetable par
variable. - Calculez la table du predictor insight graph en calculant l’incidence de la cible et la taille des groupes.
- Utilisez la fonction
create_pig_tablepour calculer la table du predictor insight graph pour la variable "gender".
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Function that creates predictor insight graph table
def create_pig_table(basetable, target, variable):
# Create groups for each variable
groups = basetable[[target,variable]].____(____)
# Calculate size and target incidence for each group
pig_table = groups[____].agg(Incidence = '____', Size = '____').reset_index()
# Return the predictor insight graph table
return pig_table
# Calculate the predictor insight graph table for the variable gender
pig_table_gender = ____(basetable, "target", ____)
# Print the result
print(pig_table_gender)