住宅価格を手計算で予測する
モデルの係数から予測値を手計算できます。実際に予測するときは predict() を使うほうがよいのですが、手計算してみると予測は魔法ではなく、単なる算術であることを確認できます。
実際、単回帰では、予測値は切片に傾きと説明変数を掛けたものを足しただけです。
$$response = intercept + slope * explanatory$$
mdl_price_vs_conv と explanatory_data は利用可能で、dplyr は読み込まれています。
この演習はコースの一部です
Rで学ぶ回帰入門
演習の手順
mdl_price_vs_convの係数を取得し、coeffsに代入します。- 切片(
coeffsの1番目の要素)を取得し、interceptに代入します。 - 傾き(
coeffsの2番目の要素)を取得し、slopeに代入します。 intercept、slope、n_convenienceを使って、price_twd_msqを手動で予測します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Get the coefficients of mdl_price_vs_conv
coeffs <- ___
# Get the intercept
intercept <- ___
# Get the slope
slope <- ___
explanatory_data %>%
mutate(
# Manually calculate the predictions
price_twd_msq = ___
)
# Compare to the results from predict()
predict(mdl_price_vs_conv, explanatory_data)