Skip to content

Support serde serialization of ensemble models - #450

Open
dbrundu wants to merge 4 commits into
rust-ml:masterfrom
dbrundu:master
Open

Support serde serialization of ensemble models#450
dbrundu wants to merge 4 commits into
rust-ml:masterfrom
dbrundu:master

Conversation

@dbrundu

@dbrundu dbrundu commented Jul 27, 2026

Copy link
Copy Markdown

A fitted ensemble could not be persisted, even though the weak learners it wraps, like DecisionTree, already can (#449).

This PR adds the Serialize/Deserialize derives to EnsembleLearner<M> and AdaBoost<M, L>, following the pattern already used in linfa-trees and linfa-clustering, without manual impl. The serde feature needs to forward to linfa-trees/serde, which is required in order to get RandomForest serializable. Also, linfa-ensemble/serde is added to the serde cargo check in checking.yml.

Three unit tests are added to cross-check round-trip predictions and parameters between the original model and the serialized/reloaded one, by using serde-json. The prediction comparison for the RandomForest model was done by iterating over all the trees by hand, to get reproducible and meaningful comparison and not be dependent by the tree majority vote, which is dependent by the HashMap iteration order.

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.89%. Comparing base (7fe5c86) to head (02c433f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #450      +/-   ##
==========================================
+ Coverage   77.53%   77.89%   +0.36%     
==========================================
  Files         106      104       -2     
  Lines        7585     7524      -61     
==========================================
- Hits         5881     5861      -20     
+ Misses       1704     1663      -41     

☔ View full report in Codecov by Harness.
📢 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.

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.

1 participant