Session Ready
Exercise

Manually calculating predictions

As with simple linear regression, you can also manually calculate the predictions from the model coefficients. The only change for the parallel slopes case is that the intercept is different for each category of the categorical explanatory variable. That means you need to consider the case when each each category occurs separately.

taiwan_real_estate, mdl_price_vs_both, and explanatory_data are available; ic_0_15, ic_15_30, ic_30_45, and slope from the previous exercise are also loaded.

Instructions
100 XP
  • Define a list, conditions, with three condition statements: check if house_age_years is "0 to 15", check if house_age_years is "15 to 30", and check if house_age_years is "30 to 45".
  • Define a list, choices, with the extracted intercepts from mdl_price_vs_both. These correspond to each of the conditions.
  • Create an array of intercepts using np.select().
  • Create prediction_data: start with explanatory_data, assign intercept as the array of intercepts, and price_twd_msq as the manually calculated predictions.