Predicting with interactions
As with every other regression model you've created, the fun part is making predictions. Fortunately, the code flow for this case is the same as the one without interactions — statsmodels
can handle calculating the interactions without any extra prompting from you. The only thing you need to remember is the trick for getting combinations of explanatory variables.
mdl_price_vs_both_inter
is available as a fitted model, itertools.product
is loaded.
This exercise is part of the course
Intermediate Regression with statsmodels in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create n_convenience as an array of numbers from 0 to 10
n_convenience = ____
# Extract the unique values of house_age_years
house_age_years = ____
# Create p as all combinations of values of n_convenience and house_age_years
p = ____
# Transform p to a DataFrame and name the columns
explanatory_data = ____
# Print it
print(explanatory_data)