quantlab.model.evaluation.r2#
- quantlab.model.evaluation.r2(pred, target)[source]#
Return the coefficient of determination
1 - SS_res / SS_tot.NaN is returned when fewer than two cells are usable or when the target is constant over the usable cells (
SS_tot == 0), because R2 is undefined in both cases.- Parameters:
- predarray_like
Predictions, any shape.
- targetarray_like
Realised values, the same shape as
pred.
Examples
>>> r2([1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 6.0]) 0.7142857142857143 >>> r2([1.0, 2.0], [3.0, 3.0]) nan