始める無料で始める

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.

この演習はコースの一部です

Intermediate Regression with statsmodels in Python

コースを見る

演習の手順

  • 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.

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# 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)
コードを編集して実行