qis.prediction_r_squared

qis.prediction_r_squared(actual, prediction, benchmark=None, weights=None)[source]

Score aligned predictions without clipping negative out-of-sample R-squared.

Parameters:
  • actual (Series) – Finite observations with a unique index.

  • prediction (Series) – Finite fitted or held-out predictions on exactly the same index.

  • benchmark (float | Series | None) – Constant or aligned benchmark predictions. None uses the weighted observed mean and is appropriate only for an in-sample diagnostic.

  • weights (Series | None) – Optional finite nonnegative objective weights, aligned to actual.

Returns:

One minus weighted prediction SSE divided by benchmark SSE; NaN for a zero denominator. For out-of-sample use a benchmark known before each test date.

Return type:

float