> "R² tells you how much of the variance in actual values is explained by your predictions. It's the statistician's favorite metric for good reason."
The Coefficient of Determination (R²) measures the proportion of variance in the actual values that is predictable from the predicted values. R² ranges from negative infinity to 1, where 1 indicates perfect predictions.
## Architecture & Physics
R² is computed as 1 minus the ratio of residual sum of squares (RSS) to total sum of squares (TSS). This is mathematically equivalent to R² = 1 - RSE, making R² the complement of Relative Squared Error.
When all actual values in the window are identical, TSS becomes zero (all values equal the mean). The implementation returns 0.0 in this case, indicating no variance to explain.
### Negative R² Values
R² can be negative when predictions are worse than simply predicting the mean. This indicates a fundamentally flawed model that should not be used.
### R² ≠ Correlation Squared (in general)
While R² equals the square of Pearson correlation for simple linear regression, this relationship does not hold for general predictions. R² can be negative; correlation squared cannot.
### High R² Doesn't Mean Good Predictions
R² measures relative fit, not absolute accuracy. A model with R² = 0.99 could still have large absolute errors if the data has high variance.