Adding interactions to the basetable
Assume that a non-profit organisation wants to launch a campaign in Spain and France, and wants to know which donors are most likely to donate. Given is a basetable with predictive variables "age", "country_Spain", "country_France" and the target "target".
For your convenience, a function auc is implemented that returns the AUC on partitioned data, taking two arguments, namely the set of variables considered and the basetable:
auc(["variable_1","variable_2"], basetable)
0.51
In this exercise, you will learn how to add interactions to the basetable and verify whether this improves the AUC of the predictive model.
Deze oefening maakt deel uit van de cursus
Intermediate Predictive Analytics in Python
Oefeninstructies
- Print the AUC of a model using
ageonly and the AUC of a model usingcountry_Spainonly. - Print the AUC of a model using
ageandcountry_Spain. - Add two interaction terms, namely
agewithcountry_Spainandagewithcountry_Franceto the basetable. - Print the AUC of a model using
age,country_Spainand the interaction terms.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Calculate AUC using age only
print(auc(["____"], basetable))
# Calculate AUC using country_Spain only
print(____(["____"], ____))
# Calculate AUC using age and country_Spain
print(____(["____", "____"], ____))
# Add interactions country_Spain x age and country_France x age
basetable["spain_age"] = ____["____"] * ____["____"]
basetable["france_age"] = ____["____"] * ____["____"]
# Calculate AUC using age, country_Spain and interactions
print(____(["____", "____", "____", "____"], ____))