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.
$$\text{response} = \text{intercept} + \text{slope} * \text{explanatory}$$
mdl_price_vs_conv and explanatory_data are available.
This exercise is part of the course
Introduction to Regression with statsmodels in Python
Exercise instructions
- Get the coefficients/parameters 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 formula, specifying the intercept, slope, andexplanatory_data. - Run the code to compare your manually calculated predictions to the results from
.predict().
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Get the coefficients of mdl_price_vs_conv
coeffs = ____
# Get the intercept
intercept = ____
# Get the slope
slope = ____
# Manually calculate the predictions
price_twd_msq = ____
print(price_twd_msq)
# Compare to the results from .predict()
print(price_twd_msq.assign(predictions_auto=mdl_price_vs_conv.predict(explanatory_data)))