-
Notifications
You must be signed in to change notification settings - Fork 13
feat(linear): Add ensemble tree model and solver-aware scoring #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
libmultilabel/linear/tree.py
Outdated
next_level.extend(zip(node.children, children_score.tolist())) | ||
|
||
cur_level = sorted(next_level, key=lambda pair: -pair[1])[:beam_width] | ||
next_level = [] | ||
|
||
num_labels = len(self.root.label_map) | ||
scores = np.zeros(num_labels) | ||
scores = np.full(num_labels, 0.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we need to modify this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my mistake, I have just checked and will revert right away
return solver_type in ["0", "6", "7"] | ||
return False | ||
|
||
def _get_scores(self, pred, parent_score=0.0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should specify the parameter type. Please see other functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the formatting issues mentioned above, please use black formatter.
What does this PR do?
(Some descriptions here...)
This pull request introduces two major enhancements to the linear tree-based models:
Key Changes:
1. Ensemble of Trees
EnsembleTreeModel
class inlibmultilabel/linear/tree.py
now manages multiple tree models.train_ensemble_tree
function handles the training ofn
separate tree models, each with a different random seed for diversity.--tree_ensemble_models
inmain.py
and integrated intolinear_trainer.py
.Example usage:
2. Corrected Scoring Logic
_is_lr
method inTreeModel
now correctly identifies all of LIBLINEAR's Logistic Regression solvers (0
,6
, and7
)._get_scores
method has been updated to use the correct scoring function based on the solver type:log_expit
to correctly accumulate log-probabilities along a path in the tree.This fix is crucial for the beam search to find the optimal labels, as the previous implementation incorrectly applied the SVM scoring logic to LR models.
Test CLI & API (
bash tests/autotest.sh
)Test APIs used by main.py.
Check API Document
If any new APIs are added, please check if the description of the APIs is added to API document.
Test quickstart & API (
bash tests/docs/test_changed_document.sh
)If any APIs in quickstarts or tutorials are modified, please run this test to check if the current examples can run correctly after the modified APIs are released.