(&self, x: &DMatrix<f64>)
| 231 | } |
| 232 | |
| 233 | pub fn predict(&self, x: &DMatrix<f64>) -> Result<Vec<u8>, SbBaggingError> { |
| 234 | if self.estimators.is_empty() { |
| 235 | return Err(SbBaggingError::EmptyInput); |
| 236 | } |
| 237 | let mut out = vec![0u8; x.nrows()]; |
| 238 | for r in 0..x.nrows() { |
| 239 | let mut votes = 0usize; |
| 240 | for est in &self.estimators { |
| 241 | let ge = x[(r, est.feature_idx)] >= est.threshold; |
| 242 | let pred_one = if est.positive_on_ge { ge } else { !ge }; |
| 243 | if pred_one { |
| 244 | votes += 1; |
| 245 | } |
| 246 | } |
| 247 | out[r] = if votes * 2 >= self.estimators.len() { 1 } else { 0 }; |
| 248 | } |
| 249 | Ok(out) |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | #[derive(Debug, Clone)] |
no test coverage detected