LoslegenKostenlos starten

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.

Diese Übung ist Teil des Kurses

<Kurs>Intermediate Predictive Analytics in Python</Kurs>
Kurs ansehen

Übungsanweisungen

  • Print the AUC of a model using age only and the AUC of a model using country_Spain only.
  • Print the AUC of a model using age and country_Spain.
  • Add two interaction terms, namely age with country_Spain and age with country_France to the basetable.
  • Print the AUC of a model using age, country_Spain and the interaction terms.

Interaktive praktische Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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(____(["____", "____", "____", "____"], ____))
Code bearbeiten und ausführen