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.
This exercise is part of the course
Intermediate Predictive Analytics in Python
Exercise instructions
- 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.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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(____(["____", "____", "____", "____"], ____))