(&mut self, _x: &[Vec<f64>], y: &[f64], sample_weight: Option<&[f64]>)
| 41 | |
| 42 | impl SimpleClassifier for ThresholdClassifier { |
| 43 | fn fit(&mut self, _x: &[Vec<f64>], y: &[f64], sample_weight: Option<&[f64]>) { |
| 44 | let mut total_w = 0.0; |
| 45 | let mut pos_w = 0.0; |
| 46 | for (i, yi) in y.iter().enumerate() { |
| 47 | let w = sample_weight.map(|sw| sw[i]).unwrap_or(1.0); |
| 48 | total_w += w; |
| 49 | if *yi == 1.0 { |
| 50 | pos_w += w; |
| 51 | } |
| 52 | } |
| 53 | self.trained_prior = if total_w > 0.0 { pos_w / total_w } else { 0.5 }; |
| 54 | } |
| 55 | |
| 56 | fn predict_proba(&self, x: &[Vec<f64>]) -> Vec<f64> { |
| 57 | x.iter() |
nothing calls this directly
no outgoing calls
no test coverage detected