Commit 9b5c424
Add AdaBoost classifier to linfa-ensemble (#427)
* feat: Add AdaBoost (Adaptive Boosting) to linfa-ensemble
Implements SAMME (Stagewise Additive Modeling using a Multiclass Exponential
loss function) algorithm for multi-class classification using ensemble learning.
## Features
- Sequential boosting with adaptive sample weighting
- Multi-class classification support (SAMME algorithm)
- Weighted voting for final predictions using model alpha values
- Automatic convergence handling and early stopping
- Resampling-based approach compatible with any base learner
## Implementation Details
- AdaBoost struct with model weights (alpha values) tracking
- AdaBoostParams following ParamGuard pattern for validation
- Configurable n_estimators and learning_rate hyperparameters
- Full trait implementations: Fit, Predict, PredictInplace
- Comprehensive error handling with proper error types
## Testing
- 12 unit tests covering parameter validation and model training
- 6 doc tests for API documentation
- Achieves 90-93% accuracy on Iris dataset with decision stumps
- Tests for different learning rates and tree depths
## Documentation
- Extensive inline documentation with algorithm explanation
- Working example (adaboost_iris.rs) with multiple configurations
- References to original AdaBoost paper (Freund & Schapire, 1997)
- Comparison with scikit-learn implementation
## Performance
- Successfully trains on Iris dataset (150 samples, 3 classes)
- Supports decision stumps (depth=1) and shallow trees
- Model weights properly reflect learner performance
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* fix: remove redundant explicit link target in rustdoc
Fixes rustdoc warning about redundant explicit links.
Changed [AdaBoost](AdaBoost) to [AdaBoost] as recommended by rustdoc linter.
* test: add tests for edge cases to improve coverage
Adds three new tests to improve code coverage:
- test_adaboost_early_stopping_on_perfect_fit: Tests early stopping on linearly separable data
- test_adaboost_single_class_error: Tests error handling for single-class datasets
- test_adaboost_classes_method: Tests that classes are properly identified
This should improve patch coverage from 81.69% to ~85%+
* style: apply rustfmt formatting
Fix import ordering and line wrapping to match rustfmt standards.
* fix: address code review feedback for AdaBoost implementation
Implements all requested changes from PR review:
1. Replace rand:: imports with ndarray_rand::rand:: for consistency
2. Change sample_weights from f32 to f64 for better precision
3. Fix learning_rate cancellation bug in weight update formula
- Previously: weight *= ((alpha / learning_rate) as f32).exp()
- Now: weight *= alpha.exp()
- This ensures learning_rate actually affects sample weight updates
4. Fix classes field to store actual labels (T::Elem) instead of usize
- Made AdaBoost struct generic over label type L
- Stores original class labels for proper type safety
5. Remove duplicate y_array definition in predict_inplace
6. Add base learner error details to error message for better debugging
7. Add test_adaboost_different_learning_rates to verify learning_rate
effects on model weights
All tests passing with no warnings or clippy issues.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Cleanup f64
* No tie breaking
* Avoid magic number
---------
Co-authored-by: Deep Rathi <deeprathi222@gmail.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent db3cade commit 9b5c424
4 files changed
Lines changed: 888 additions & 0 deletions
File tree
- algorithms/linfa-ensemble
- examples
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
0 commit comments