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 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.
Questo esercizio fa parte del corso
Intermediate Regression with statsmodels in Python
Istruzioni dell'esercizio
- Define a list,
conditions, with three conditional statements:house_age_yearsis"0 to 15",house_age_yearsis"15 to 30", andhouse_age_yearsis"30 to 45". - Define a list,
choices, with the extracted intercepts frommdl_price_vs_both. These correspond to each of the conditions. - Create an array of intercepts using
np.select(). - Create
prediction_data: start withexplanatory_data, assigninterceptas the array of intercepts, andprice_twd_msqas the manually calculated predictions.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Define conditions
conditions = [____]
# Define choices
choices = [____]
# Create array of intercepts for each house_age_year category
intercept = ____(____, ____)
# Create prediction_data with columns intercept and price_twd_msq
prediction_data = ____.____(
____ = ____,
____ = ____ + ____ * ____[____])
print(prediction_data)