Regrouper toutes les tables du predictor insight graph
Dans l’exercice précédent, vous avez construit une fonction qui calcule la table du predictor insight graph pour une variable donnée comme suit :
pig_table = create_pig_table(basetable, "target","variable")
Si vous souhaitez calculer la table du predictor insight graph pour plusieurs variables en une seule fois, il est judicieux de les stocker dans un dictionnaire. Vous pouvez créer un nouveau dictionnaire avec dictionary = {}, ajouter des éléments avec une clé via dictionary["key"] = value et récupérer des éléments en utilisant la clé print(dictionary["key"]).
Cet exercice fait partie du cours
Introduction à l’analytique prédictive en Python
Instructions
- Créez un dictionnaire vide
pig_tables. - Pour chaque variable, créez une table du predictor insight graph.
- Pour chaque variable, ajoutez cette table du predictor insight graph au dictionnaire, en utilisant comme clé le nom de la variable.
- Affichez la table du predictor insight graph de
disc_time_since_last_gift.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Create the list of variables for our predictor insight graph tables
variables = ["income","gender","disc_mean_gift","disc_time_since_last_gift"]
# Create an empty dictionary
pig_tables = ____
# Loop through the variables
for variable in variables:
# Create a predictor insight graph table
pig_table = ____(basetable, ____, ____)
# Add the table to the dictionary
pig_tables[____] = ____
# Print the predictor insight graph table of the variable "disc_time_since_last_gift"
print(pig_tables["____"])