How do you interpret the coefficient of determination, R-squared?
Instruction: Explain the meaning of R-squared in the context of regression analysis.
Updated
Example Answer
R-squared compares a model’s squared prediction error with the error from predicting the mean of the observed target values. For a nonconstant target, it is one minus the model’s residual sum of squares divided by the target’s total sum of squares. One means perfect predictions; zero means the same squared error as that mean baseline; a negative value means worse error.
With ordinary least squares fitted and evaluated on the same data, including an intercept, R-squared is normally between zero and one. That bound does not hold for arbitrary predictions or held-out evaluation. I would report it alongside an error metric in the target’s units and evaluate on data separated appropriately for the application. A high R-squared is not evidence of causation, and adding predictors can raise training R-squared without improving generalization.
Worked example
For y = [1, 2, 3] and predictions [3, 3, 3], squared error is 5 and the mean-baseline error is 2, so R² = 1 − 5/2 = −1.5. For a constant target, the formula’s denominator is zero; check the library’s handling.
Why this works
It defines the baseline precisely and gives the important exception to the familiar range.