LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Intermediate Regression with statsmodels in Python

Kurs anzeigen

Anleitung zur Übung

  • Define a list, conditions, with three conditional statements: house_age_years is "0 to 15", house_age_years is "15 to 30", and 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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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)
Code bearbeiten und ausführen