What does a residual represent in a regression model?
Think about what remains unexplained after prediction.
A residual is the difference between the actual observed value and the value predicted by the regression model. It shows the error for each data point.
Given the true values and predicted values below, what is the list of residuals?
true_values = [10, 15, 20, 25] predicted_values = [8, 14, 22, 24] residuals = [true - pred for true, pred in zip(true_values, predicted_values)] print(residuals)
Subtract predicted from true values element-wise.
Residuals are calculated as true value minus predicted value for each pair.
Which metric best summarizes the average magnitude of residuals without canceling positive and negative errors?
Think about a metric that treats all errors equally regardless of sign.
MAE calculates the average absolute difference between predicted and actual values, so it does not cancel out positive and negative residuals.
What error will this code produce when calculating residuals?
true_vals = [5, 7, 9] pred_vals = [4, 6] residuals = [t - p for t, p in zip(true_vals, pred_vals)] print(residuals)
Recall how zip works with lists of different lengths.
zip stops at the shortest list length, so no error occurs and residuals list has length 2.
You observe a pattern in residuals that increases with predicted values, indicating heteroscedasticity. Which model adjustment is best to address this?
Consider methods that handle changing variance in residuals.
Weighted least squares regression accounts for heteroscedasticity by weighting points inversely to their variance, improving model fit.
