Module smartcore::metrics::r2

source ·
Expand description

Coefficient of determination (R2). Coefficient of Determination (R2)

Coefficient of determination, denoted R2 is the proportion of the variance in the dependent variable that can be explained be explanatory (independent) variable(s).

\[R^2(y, \hat{y}) = 1 - \frac{\sum_{i=1}^{n}(y_i - \hat{y_i})^2}{\sum_{i=1}^{n}(y_i - \bar{y})^2} \]

where \(\hat{y}\) are predictions, \(y\) are true target values, \(\bar{y}\) is the mean of the observed data

Example:

use smartcore::metrics::mean_absolute_error::MeanAbsoluteError;
use smartcore::metrics::Metrics;
let y_pred: Vec<f64> = vec![3., -0.5, 2., 7.];
let y_true: Vec<f64> = vec![2.5, 0.0, 2., 8.];

let mse: f64 = MeanAbsoluteError::new().get_score( &y_true, &y_pred);

Structs

  • Coefficient of Determination (R2)