Introductie tot Predictive Analytics in Python
Nele Verbiest, Ph.D
Data Scientist @PythonPredictions
| disc_mean_gift | Incidentie | Omvang |
|---|---|---|
| [2, 78] | 0.013042 | 20013 |
| (78, 87] | 0.029554 | 19997 |
| (87, 94] | 0.040831 | 20034 |
| (94, 103] | 0.063563 | 20405 |
| (103, 197] | 0.103524 | 19551 |
# Laad de numpy-module import numpy as np # Functie die de predictor insight-graphtabel berekent def create_pig_table(df, target, variable):# Groepeer op de variabele die je wilt plotten groups = df[[target,variable]].groupby(variable)# Bereken de omvang en incidentie van elke groep pig_table = groups[target].agg(Incidence = 'mean').reset_index() return pig_tableprint(create_pig_table(basetable,"target","country")
country Incidence Size
India 0.050934 49849
UK 0.050512 10057
USA 0.048486 40094
variables = ["country", "gender", "disc_mean_gift", "age"]# Lege dictionary. pig_tables = {}# Loop over alle variabelen for variable in variables:# Maak de predictor insight-graphtabel pig_table = create_pig_table(basetable, "target", variable)# Sla de tabel op in de dictionary pig_tables[variable] = pig_tableprint(create_pig_table(basetable,"target","country")
country Incidence Size
India 0.050934 49849
UK 0.050512 10057
USA 0.048486 40094
Introductie tot Predictive Analytics in Python