Calculate an event target
=======
You are organising a charity event and want to predict which donors are most likely to attend this event. You organized a similar event in the past, so you can use that information to construct a predictive model. Given is a list population
with unique donor ids for this basetable and a list attend_event
with donors in the population that attended this past event.
In this exercise you will construct a basetable with two columns: the donor_id
and the target
, which is 1 if the donor attended the event and 0 otherwise.
Este ejercicio forma parte del curso
Intermediate Predictive Analytics in Python
Instrucciones del ejercicio
- Construct a pandas dataframe basetable that has one row for each donor in
population
and one columndonor_id
with the donor's ID. - Add the target as a column to the basetable. The target is 1 if the donor attended the event and 0 otherwise.
- Calculate and print the target incidence, i.e. the number of times the target is 1 divided by the number of rows in the basetable.
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
# Basetable with one column: donor_id
basetable = pd.DataFrame(____, columns=["____"])
# Add target to the basetable
basetable["target"] = pd.Series([____ if donor_id in ____ else ____ for donor_id in basetable["donor_id"]])
# Calculate and print the target incidence
print(round(____["____"].sum() / len(____), 2))