Get startedGet started for free

Calculating average incidences

The most important column in the predictor insight graph table is the target incidence column. This column shows the average target value for each group.

This exercise is part of the course

Introduction to Predictive Analytics in Python

View Course

Exercise instructions

  • Create a DataFrame basetable_income that only contains the variables target and income.
  • Group this DataFrame by income.
  • Calculate the average target incidence for each group in income.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Select the income and target columns
basetable_income = basetable[["____","____"]]

# Group basetable_income by income
groups = basetable_income.____("____")

# Calculate the target incidence and print the result
incidence = groups["____"].agg(Incidence = '____').reset_index()
print(incidence)
Edit and Run Code