De predictor insight-graphtabel voorbereiden

Introductie tot Predictive Analytics in Python

Nele Verbiest, Ph.D

Data Scientist @PythonPredictions

De predictor insight-graphtabel

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
Introductie tot Predictive Analytics in Python

De predictor insight-graphtabel berekenen

# 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_table
print(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

Meerdere predictor insight-graphtabellen berekenen

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_table
print(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

Laten we oefenen!

Introductie tot Predictive Analytics in Python

Preparing Video For Download...