Skip to content
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

Improve confusion matrix plot #5273

Merged
merged 3 commits into from Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions mlflow/models/evaluation/default_evaluator.py
Expand Up @@ -599,10 +599,18 @@ def _evaluate_classifier(self):
)

def plot_confusion_matrix():
sk_metrics.ConfusionMatrixDisplay(
confusion_matrix=confusion_matrix,
display_labels=self.label_list,
).plot(cmap="Blues")
import matplotlib

with matplotlib.rc_context(
{
"font.size": min(10, 50.0 / self.num_classes),
"axes.labelsize": 10,
}
):
sk_metrics.ConfusionMatrixDisplay(
confusion_matrix=confusion_matrix,
display_labels=self.label_list,
).plot(cmap="Blues")

if hasattr(sk_metrics, "ConfusionMatrixDisplay"):
self._log_image_artifact(
Expand Down
14 changes: 13 additions & 1 deletion mlflow/sklearn/utils.py
Expand Up @@ -288,10 +288,22 @@ def _get_classifier_artifacts(fitted_estimator, prefix, X, y_true, sample_weight
if not _is_plotting_supported():
return []

def plot_confusion_matrix(*args, **kwargs):
import matplotlib

num_classes = len(set(y_true))
with matplotlib.rc_context(
{
"font.size": min(10.0, 50.0 / num_classes),
"axes.labelsize": 10.0,
}
):
return sklearn.metrics.plot_confusion_matrix(*args, **kwargs)

classifier_artifacts = [
_SklearnArtifact(
name=prefix + "confusion_matrix",
function=sklearn.metrics.plot_confusion_matrix,
function=plot_confusion_matrix,
arguments=dict(
estimator=fitted_estimator,
X=X,
Expand Down