Calculate the R-squared coefficient of determination for a regression model.
R-squared (the coefficient of determination) measures the proportion of variance in the actual values that is explained by the model's predictions: R² = 1 − SS_res/SS_tot, where SS_res is the residual (unexplained) sum of squared errors and SS_tot is the total sum of squared deviations from the mean. R² = 1 means the model perfectly explains all variance, R² = 0 means the model is no better than always predicting the mean, and R² can go negative when the model performs worse than that naive baseline.
R^2 = 1 - SS_res / SS_tot
Yes — a negative R² means the model's predictions are worse than simply predicting the mean of the actual values every time, which can happen with a poorly fit or overfit model evaluated on new data.
Not necessarily — R² can be inflated by adding more predictors even if they're not meaningful (which is why Adjusted R² exists), and a high R² doesn't guarantee the model generalizes well to new, unseen data.
For simple linear regression with one predictor, R² equals the square of the Pearson correlation coefficient between actual and predicted values, though this equivalence doesn't hold in general for arbitrary prediction models.