CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Intermediate Regression with statsmodels in Python

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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)
Modifier et exécuter le code