Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Intermediate Regression with statsmodels in Python

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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)
Code bewerken en uitvoeren