"f1" score, the model still considers "accuracy" #646#822
Open
Jdmesa wants to merge 1 commit into
Open
Conversation
When ml_task is multiclass_classification and the user selects 'f1' as eval_metric, XGBoost was defaulting to 'accuracy' internally because 'f1' is not a native XGBoost metric for multiclass. This fix ensures f1 and accuracy are explicitly routed as custom metrics in the multiclass case, consistent with how LightGBM handles it. Adds a test case covering eval_metric='f1' in multiclass with sensitive features.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
ml_task="multiclass_classification"and settingeval_metric="f1",the XGBoost algorithm was internally defaulting to
accuracyas its evaluationmetric instead of respecting the user's choice.
This happened because the
xgboost_eval_metric()function insupervised/algorithms/xgboost.pyonly handled thelogloss → mloglossmapping for multiclass, leaving
f1andaccuracywithout explicit routingas custom metrics. As a result, XGBoost did not recognize
f1as a nativemetric for multiclass tasks and silently fell back to
accuracy.Fix
Added an explicit
elifbranch inxgboost_eval_metric()to handlef1and
accuracyas custom metrics whenml_taskismulticlass_classification,consistent with how
lightgbm_eval_metric()already handles this case insupervised/algorithms/lightgbm.py.Changes
supervised/algorithms/xgboost.py: updatedxgboost_eval_metric()toexplicitly route
f1andaccuracyas custom metrics for multiclass.tests/tests_fairness/test_multi_class_classification.py: addedtest_with_f1_metric()to cover the multiclass case witheval_metric="f1"and sensitive features.