pub fn label_average(dv: &DataVec, len: usize) -> ValueType
Expand description

Return the weighted label average for first n data in data vector.

Example

use gbdt::decision_tree::{DataVec, Data, VALUE_TYPE_UNKNOWN};
use gbdt::fitness::{label_average, almost_equal};
let mut dv: DataVec = Vec::new();
dv.push(Data {
    feature: Vec::new(),
    target: 1.0,
    weight: 0.1,
    label: 1.0,
    residual: 0.5,
    initial_guess: VALUE_TYPE_UNKNOWN,
});
dv.push(Data {
    feature: Vec::new(),
    target: 1.0,
    weight: 0.2,
    label: 0.0,
    residual: 0.5,
    initial_guess: VALUE_TYPE_UNKNOWN,
});
dv.push(Data {
    feature: Vec::new(),
    target: 0.0,
    weight: 0.3,
    label: 1.0,
    residual: 0.5,
    initial_guess: VALUE_TYPE_UNKNOWN,
});
dv.push(Data {
    feature: Vec::new(),
    target: 0.0,
    weight: 0.4,
    label: 0.0,
    residual: 0.5,
    initial_guess: VALUE_TYPE_UNKNOWN,
});
assert!(almost_equal(0.4, label_average(&dv, dv.len())));

Panic

If the specified length is greater than the length of data vector, it will panic.