-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
XGBoost autologging: support per-class importance plots #4523
Conversation
Signed-off-by: dbczumar <corey.zumar@databricks.com>
Signed-off-by: dbczumar <corey.zumar@databricks.com>
Signed-off-by: dbczumar <corey.zumar@databricks.com>
0588f67
to
f3ce845
Compare
mlflow/xgboost.py
Outdated
importances_per_class_by_feature = np.array( | ||
[[importance] for importance in importances_per_class_by_feature] | ||
) |
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.
importances_per_class_by_feature = np.array( | |
[[importance] for importance in importances_per_class_by_feature] | |
) | |
importances_per_class_by_feature = np.array( | |
[[importance] for importance in importances_per_class_by_feature[indices]] | |
) |
Can we sort importance
as well?
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.
mlflow/xgboost.py
Outdated
feature_yloc + offset, | ||
class_importance, | ||
align="center", | ||
height=(0.5 / num_classes), |
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.
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.
Great suggestion! Done!
for class_idx, (offset, class_importance) in enumerate( | ||
zip(offsets_per_yloc, importances_per_class) | ||
): | ||
(bar,) = ax.barh( |
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.
Nice unpacking :)
mlflow/xgboost.py
Outdated
else: | ||
label_classes_on_plot = True |
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.
Can we sort a 2D importance matrix (that linear boosters generates) as well?
import numpy as np
features = np.array(["a", "b", "c"])
importance = [
# class0, class1, class2
[7, 8, 9], # a
[4, 5, 6], # b
[1, 2, 3], # c
]
importances_per_class_by_feature = np.array(importance)
abs_sum = np.abs(importances_per_class_by_feature).sum(axis=1)
# or abs_mean = np.abs(importances_per_class_by_feature).mean(axis=1)
indices = np.argsort(abs_sum)
print(importances_per_class_by_feature[indices])
# [[1 2 3]
# [4 5 6]
# [7 8 9]]
print(features[indices])
# ['c' 'b' 'a']
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.
Signed-off-by: dbczumar <corey.zumar@databricks.com>
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.
@harupy Thanks for the awesome review feedback! I've addressed your comments. Can you take another look?
mlflow/xgboost.py
Outdated
feature_yloc + offset, | ||
class_importance, | ||
align="center", | ||
height=(0.5 / num_classes), |
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.
Great suggestion! Done!
mlflow/xgboost.py
Outdated
importances_per_class_by_feature = np.array( | ||
[[importance] for importance in importances_per_class_by_feature] | ||
) |
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.
mlflow/xgboost.py
Outdated
else: | ||
label_classes_on_plot = True |
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.
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.
LGTM!
What changes are proposed in this pull request?
XGBoost 1.15.0-dev introduced support for importance computation on linear estimators. These estimators return importance values for each (feature, class) pair as a
num_features
-by-num_classes
matrix. This PR introduces extends feature importance plotting support in XGBoost autologging to handle this new importance value format.How is this patch tested?
Release Notes
Add XGBoost autologging support for multi-class feature importance plots
Is this a user-facing change?
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/artifacts
: Artifact stores and artifact loggingarea/build
: Build and test infrastructure for MLflowarea/docs
: MLflow documentation pagesarea/examples
: Example codearea/model-registry
: Model Registry service, APIs, and the fluent client calls for Model Registryarea/models
: MLmodel format, model serialization/deserialization, flavorsarea/projects
: MLproject format, project running backendsarea/scoring
: Local serving, model deployment tools, spark UDFsarea/server-infra
: MLflow server, JavaScript dev serverarea/tracking
: Tracking Service, tracking client APIs, autologgingInterface
area/uiux
: Front-end, user experience, JavaScript, plottingarea/docker
: Docker use across MLflow's components, such as MLflow Projects and MLflow Modelsarea/sqlalchemy
: Use of SQLAlchemy in the Tracking Service or Model Registryarea/windows
: Windows supportLanguage
language/r
: R APIs and clientslanguage/java
: Java APIs and clientslanguage/new
: Proposals for new client languagesIntegrations
integrations/azure
: Azure and Azure ML integrationsintegrations/sagemaker
: SageMaker integrationsintegrations/databricks
: Databricks integrationsHow should the PR be classified in the release notes? Choose one:
rn/breaking-change
- The PR will be mentioned in the "Breaking Changes" sectionrn/none
- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/feature
- A new user-facing feature worth mentioning in the release notesrn/bug-fix
- A user-facing bug fix worth mentioning in the release notesrn/documentation
- A user-facing documentation change worth mentioning in the release notes