Skip to content

R²(log) — R² in log₁₀ Space

\[ R^2_{\log} = 1 - \frac{\sum_i (\log_{10} y_{\text{true},i} - \log_{10} y_{\text{pred},i})^2} {\sum_i (\log_{10} y_{\text{true},i} - \overline{\log_{10} y_{\text{true}}})^2} \]

Only Samples where both \(y_{\text{true}} > 0\) and \(y_{\text{pred}} > 0\) are included.

Implementation: custom — sklearn.metrics.r2_score applied to the log₁₀-transformed values.

Running example:

  1. Transform true values: \(\log_{10}(y_{\text{true}}) \approx [0.699, 1.301, 1.699, 2.000, 2.301]\)
  2. Transform predictions: \(\log_{10}(y_{\text{pred}}) \approx [0.778, 1.255, 1.740, 1.954, 2.342]\)
  3. Residuals in log space: \(\approx [-0.079, 0.046, -0.041, 0.046, -0.041]\); \(SS_{\text{res}} \approx 0.0139\)
  4. Mean \(\log_{10}(y_{\text{true}}) = 1.600\); \(SS_{\text{tot}} \approx 1.562\)
  5. Result: \(R^2_{\log} = 1 - 0.0139 / 1.562 \approx 0.991\)

Which number ends up in the report?

Two code paths can produce this key, and they do not apply the same rules.

Target transform Source Positivity mask? 50 % rule?
none (or yeo-johnson) log diagnostics yes yes
log10 transform-space metrics no — the transform already guarantees it no
ln / log1p transform-space metrics, keyed r2_ln / r2_log1p no no

With a log10 target transform the model is already fitted in log space, so the value is computed there directly: only non-finite rows are dropped, and neither the positivity mask nor the 50 % rule from above applies.

With ln or log1p the transform-space column is named r2_ln / r2_log1p, and r2_log10 is not produced by that path at all — even though it can still carry a weight in training.metric_weights, where the Skill Score computes it separately over the positive subset. Read the column name, not the metric name.

Interpretation

R²(log) measures the fraction of variance in \(\log_{10}(y_{\text{true}})\) explained by the model. A multiplicative error of ×2 is treated the same regardless of whether the true value is 1 or 10 000. This makes R²(log) the natural counterpart to R² for targets that span several orders of magnitude (e.g. hardness, conductivity, elastic modulus).

When to use

  • The Target distribution covers multiple orders of magnitude.
  • Errors are better described as multiplicative factors than additive offsets.
  • As the primary fit quality indicator alongside OME for log-scale targets.

Disadvantages

  • Undefined for non-positive predictions or true values; such Samples are dropped. The count is logged only when a logger is passed, so do not rely on a warning.
  • Cannot be directly compared to R² computed in the original space.
  • Communicates explained variance in log space, not in the original unit — always state which space was used in reports.

Using R²(log) as a training objective (metric_weights)

r2_log10 can be set as a weight in training.metric_weights (default 0.0). Because R²(log) requires strictly positive targets, it is subject to the positivity rule, and two checks apply:

Per scoring call (skip). When 50 % or fewer of that call's y_true values are strictly positive (each fold, each round), the component is skipped: its weight is dropped and the remaining weights are renormalised, so it neither contributes nor dampens the score.

At run start (fail-fast). y_train is tested once. If every metric with weight > 0 is undefined there, training aborts with a ValueError before any model is trained; otherwise the run continues with a warning.

The same positivity rule applies to the companion metrics rmse_log10 and medae_log10.

Relationship to other log-space metrics

When the model is trained in log₁₀ space (e.g. the pipeline applies a log10 transform), COREMat computes a full set of log-space metrics — mae_log10, rmse_log10, r2_log10, evs_log10, medae_log10, me_log10 — as suffixed variants of the standard metrics. R²(log) is the most interpretable of these because its scale (0–1) is familiar.

Log-transformation notes

COREMat supports two evaluation modes for transformed targets:

  1. Metrics in log space (r2_log10, mae_log10, …): computed directly on \(\log_{10}(y)\). Errors represent multiplicative/factorial deviations.
  2. Metrics in original space after back-transform: predictions are back-transformed (\(y_{\text{pred}} = 10^{\hat{y}}\)) before metric computation. Errors are in original units.

Always state which mode was used in reports. Mixing log-space and original-space metrics in the same table leads to incorrect comparisons.

Compute cost

Low — two passes over predictions (after log transform).


← Back to Metrics index