Skip to content

Conversation

@relf
Copy link
Member

@relf relf commented Dec 22, 2025

follow-up of #423

rathideep22 and others added 9 commits December 8, 2025 22:46
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>
Fixes rustdoc warning about redundant explicit links.
Changed [AdaBoost](AdaBoost) to [AdaBoost] as recommended by rustdoc linter.
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%+
Fix import ordering and line wrapping to match rustfmt standards.
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>
@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

❌ Patch coverage is 85.00000% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.00%. Comparing base (db3cade) to head (3ef3639).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
algorithms/linfa-ensemble/src/adaboost.rs 85.45% 16 Missing ⚠️
...orithms/linfa-ensemble/src/adaboost_hyperparams.rs 83.33% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #427      +/-   ##
==========================================
+ Coverage   76.92%   77.00%   +0.07%     
==========================================
  Files         104      106       +2     
  Lines        7321     7461     +140     
==========================================
+ Hits         5632     5745     +113     
- Misses       1689     1716      +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@relf relf marked this pull request as ready for review December 22, 2025 13:01
@relf relf merged commit 9b5c424 into rust-ml:master Dec 22, 2025
21 checks passed
@relf relf deleted the pr-423-follow-up branch December 22, 2025 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants