1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
use super::mean::Mean; /// The accuracy is the proportion of examples where predicted == label. #[derive(Default)] pub struct Accuracy(Mean); impl Accuracy { pub fn new() -> Accuracy { Accuracy::default() } } impl Accuracy { pub fn update(&mut self, value: (usize, usize)) { self.0.update(if value.0 == value.1 { 1.0 } else { 0.0 }) } pub fn merge(&mut self, other: Accuracy) { self.0.merge(other.0) } pub fn finalize(self) -> Option<f32> { self.0.finalize() } }