Manually predicting house prices
You can manually calculate the predictions from the model coefficients. When making predictions in real life, it is better to use predict(), but doing this manually is helpful to reassure yourself that predictions aren't magic—they are simply arithmetic.
In fact, for a simple linear regression, the predicted value is just the intercept plus the slope times the explanatory variable.
$$response = intercept + slope * explanatory$$
mdl_price_vs_conv and explanatory_data are available, and dplyr is loaded.
Questo esercizio fa parte del corso
Introduction to Regression in R
Istruzioni dell'esercizio
- Get the coefficients of
mdl_price_vs_conv, assigning tocoeffs. - Get the intercept, which is the first element of
coeffs, assigning tointercept. - Get the slope, which is the second element of
coeffs, assigning toslope. - Manually predict
price_twd_msqusing the intercept, slope, andn_convenience.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# 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)