Sestavení tabulky predictor insight graphu
V předchozím cvičení jsi se naučil/a, jak vypočítat sloupec incidence pro tabulku predictor insight graphu. V tomto cvičení přidáš také velikosti skupin a vše zabalíš do funkce, která vrátí tabulku predictor insight graphu pro danou proměnnou.
Toto cvičení je součástí kurzu
Introduction to Predictive Analytics in Python
Pokyny k cvičení
- Seskup základní tabulku podle
variable. - Vypočítej tabulku predictor insight graphu tak, že určíš cílovou incidenci a velikosti skupin.
- Pomocí funkce
create_pig_tablevypočítej tabulku predictor insight graphu pro proměnnou "gender".
Interaktivní cvičení na vyzkoušení si v praxi
Vyzkoušejte si toto cvičení dokončením tohoto ukázkového kódu.
# 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)