R-Squared (R²) Calculator
Calculate the R-squared (coefficient of determination) for a regression model's predictions.
Inputs
Comma-separated actual (true) values.
Comma-separated predicted values, same order and count as actual.
R² (Coefficient of Determination)
0.9486
Residual Sum of Squares
1.5000
Total Sum of Squares
29.1875
Step by step
Residual sum of squares: SS_res = Σ(y_i − ŷ_i)²
Σ(y_i − ŷ_i)²
= 1.5000
Total sum of squares: SS_tot = Σ(y_i − ȳ)²
Σ(y_i − 2.8750)²
= 29.1875
R²: 1 − SS_res / SS_tot
1 − (1.5000 ÷ 29.1875)
= 0.9486
How it works
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.
Formula
R^2 = 1 - SS_res / SS_tot
- SS_{res}
- Residual sum of squares: sum((y_i - y_hat_i)^2)
- SS_{tot}
- Total sum of squares: sum((y_i - y_mean)^2)
Frequently Asked Questions
Can R² be negative?
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.
Does a high R² always mean a good model?
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.
How is R² related to correlation?
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.