pub fn bias_variance_noise(
y_true: &[f64],
per_model_predictions: &[Vec<f64>],
y_expected: Option<&[f64]>,
) -> Result<BiasVarianceNoise, EnsembleError>Expand description
Bias², variance, noise and MSE of an ensemble’s predictions, averaged over observations.
per_model_predictions holds one row per model, each as long as y_true. variance is
the population variance of the models’ predictions around their mean, per observation.
Pass y_expected (the noiseless target E[y|x], known in simulation studies) to split
the irreducible noise out of the bias; see BiasVarianceNoise for the formulas. Without
it noise is None, because noise cannot be separated from bias using observed labels
alone.
use openquant::ensemble_methods::bias_variance_noise;
// Two models, two observations; the ensemble mean is [2, 2].
let preds = [vec![1.0, 3.0], vec![3.0, 1.0]];
let d = bias_variance_noise(&[1.0, 2.0], &preds, None)?;
assert_eq!((d.bias_sq, d.variance, d.noise, d.mse), (0.5, 1.0, None, 1.5));
// With the noiseless target the noise is split out of the bias.
let d = bias_variance_noise(&[1.0, 2.0], &preds, Some(&[1.5, 2.5]))?;
assert_eq!((d.bias_sq, d.variance, d.noise), (0.25, 1.0, Some(0.25)));
assert_eq!(d.bias_sq + d.variance + d.noise.unwrap(), d.mse);§Errors
EnsembleError::Emptyfor an emptyy_trueor no model rows.EnsembleError::LengthMismatch("prediction")if a model row’s length differs fromy_true;LengthMismatch("y_expected")ify_expected’s does.