Tracer la taille des groupes
Le predictor insight graph fournit des informations sur les variables prédictives. Chaque variable découpe la population en plusieurs groupes. Le predictor insight graph affiche une courbe qui montre l’incidence moyenne de la cible pour chaque groupe, et des barres qui indiquent la taille des groupes. Dans cet exercice, vous allez apprendre à écrire et à appliquer une fonction qui trace un predictor insight graph à partir d’une table de predictor insight graph.
Cet exercice fait partie du cours
Introduction à l’analytique prédictive en Python
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# The function to plot a predictor insight graph
def plot_pig(pig_table, variable):
# Plot formatting
plt.ylabel("Size", rotation=0, rotation_mode="anchor", ha="right")
# Plot the bars with sizes
pig_table["____"].plot(kind="bar", width=0.5, color="lightgray", edgecolor="none")
# Plot the incidence line on secondary axis
pig_table["____"].plot(secondary_y=True)
# Plot formatting
plt.xticks(np.arange(len(pig_table)), pig_table[variable])
plt.xlim([-0.5, len(pig_table) - 0.5])
plt.ylabel("Incidence", rotation=0, rotation_mode="anchor", ha="left")
# Show the graph
plt.show()