()
| 163 | |
| 164 | #[test] |
| 165 | fn test_sb_classifier() { |
| 166 | let (x, y, _, _ind) = synthetic_dataset(); |
| 167 | let split = (x.nrows() as f64 * 0.6) as usize; |
| 168 | let x_train = x.rows(0, split).into_owned(); |
| 169 | let x_test = x.rows(split, x.nrows() - split).into_owned(); |
| 170 | let y_train = &y[0..split]; |
| 171 | let y_test = &y[split..]; |
| 172 | |
| 173 | let mut sb = SequentiallyBootstrappedBaggingClassifier::new(1); |
| 174 | sb.n_estimators = 100; |
| 175 | sb.max_features = MaxFeatures::Float(1.0); |
| 176 | sb.oob_score = true; |
| 177 | |
| 178 | // indicator matrix needs the same number of labels as rows in train set |
| 179 | let bar_index: Vec<usize> = (0..split).collect(); |
| 180 | let t1: Vec<(usize, usize)> = |
| 181 | (0..split.saturating_sub(4)).step_by(2).map(|s| (s, s + 4)).collect(); |
| 182 | let ind_train = get_ind_matrix(&t1, &bar_index); |
| 183 | |
| 184 | sb.fit(&x_train, y_train, &ind_train, None).unwrap(); |
| 185 | let preds = sb.predict(&x_test).unwrap(); |
| 186 | |
| 187 | let acc = preds.iter().zip(y_test.iter()).filter(|(p, t)| **p == **t).count() as f64 |
| 188 | / y_test.len() as f64; |
| 189 | |
| 190 | assert!(acc >= 0.55, "acc={acc}"); |
| 191 | assert!(sb.oob_score_value.unwrap_or(0.0).is_finite()); |
| 192 | } |
| 193 | |
| 194 | #[test] |
| 195 | fn test_sb_regressor() { |
nothing calls this directly
no test coverage detected