Tracer les incidences
L’élément le plus important d’un predictor insight graph est la valeur d’incidence. Pour chaque groupe de la population par rapport à une variable donnée, les incidences reflètent le pourcentage de cibles dans ce groupe. Dans cet exercice, vous allez écrire une fonction Python qui trace les valeurs d’incidence d’une variable, à partir de la table du 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.
import matplotlib.pyplot as plt
import numpy as np
# The function to plot a predictor insight graph.
def plot_incidence(pig_table,variable):
# Plot the incidence line
____["____"].plot()
# Formatting the predictor insight graph
plt.xticks(np.arange(len(pig_table)), pig_table[variable])
plt.xlim([-0.5, len(pig_table) - 0.5])
plt.ylim([0, max(pig_table["Incidence"] * 2)])
plt.ylabel("Incidence", rotation=0, rotation_mode="anchor", ha="right")
plt.xlabel(variable)
# Show the graph
plt.show()