Repository: mlflow/mlflow

Issue:
Replace scikit-learn plotting fuctions with plotting class methods
Plotting functions in scikit-learn (e.g. `plot_confusion_matrix`) are deprecated in 1.0 and will be removed in 1.2. They should be replaced with plotting class methods (e.g. `ConfusionMatrixDisplay.from_predictions`).

https://github.com/mlflow/mlflow/blob/1ddb2c9b5ace0fa605195a4b14c595e274a8c384/mlflow/sklearn/utils.py#L313

For example, the code above can be fixed as follows:

```python
if Version(sklearn.__version__) >= Version("1.0"):
    return ConfusionMatrixDisplay.from_predictions((*args, **kwargs) )
else:
    return sklearn.metrics.plot_confusion_matrix(*args, **kwargs)
```

## Deprecation warnings

https://github.com/mlflow/mlflow/runs/5766838748?check_suite_focus=true#step:12:188

```
  /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/sklearn/utils/deprecation.py:87: FutureWarning: Function plot_confusion_matrix is deprecated; Function `plot_confusion_matrix` is deprecated in 1.0 and will be removed in 1.2. Use one of the class methods: ConfusionMatrixDisplay.from_predictions or ConfusionMatrixDisplay.from_estimator.
    warnings.warn(msg, category=FutureWarning)

tests/sklearn/test_sklearn_autolog.py::test_eval_and_log_metrics_for_binary_classifier
tests/sklearn/test_sklearn_autolog.py::test_eval_and_log_metrics_matches_training_metrics
  /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/sklearn/utils/deprecation.py:87: FutureWarning: Function plot_roc_curve is deprecated; Function :func:`plot_roc_curve` is deprecated in 1.0 and will be removed in 1.2. Use one of the class methods: :meth:`sklearn.metric.RocCurveDisplay.from_predictions` or :meth:`sklearn.metric.RocCurveDisplay.from_estimator`.
    warnings.warn(msg, category=FutureWarning)

tests/sklearn/test_sklearn_autolog.py::test_eval_and_log_metrics_for_binary_classifier
tests/sklearn/test_sklearn_autolog.py::test_eval_and_log_metrics_matches_training_metrics
  /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/sklearn/utils/deprecation.py:87: FutureWarning: Function plot_precision_recall_curve is deprecated; Function `plot_precision_recall_curve` is deprecated in 1.0 and will be removed in 1.2. Use one of the class methods: PrecisionRecallDisplay.from_predictions or PrecisionRecallDisplay.from_estimator.
    warnings.warn(msg, category=FutureWarning)
```


Discussion:
cc @ktksq
@harupy  I'll fix this issue!
@ktksq Awesome, looking forward to your PR!
@ktksq Are you still working on this or not?
Can I pick this up? @harupy 

Resolving patch:
diff --git a/mlflow/sklearn/utils.py b/mlflow/sklearn/utils.py
--- a/mlflow/sklearn/utils.py
+++ b/mlflow/sklearn/utils.py
@@ -295,6 +295,8 @@ def _get_classifier_artifacts(fitted_estimator, prefix, X, y_true, sample_weight
     if not _is_plotting_supported():
         return []
 
+    is_plot_function_deprecated = Version(sklearn.__version__) >= Version("1.0")
+
     def plot_confusion_matrix(*args, **kwargs):
         import matplotlib
 
@@ -310,8 +312,13 @@ def plot_confusion_matrix(*args, **kwargs):
                 "axes.labelsize": 10.0,
             }
         ):
-            return sklearn.metrics.plot_confusion_matrix(*args, **kwargs)
+            return (
+                sklearn.metrics.ConfusionMatrixDisplay.from_estimator(*args, **kwargs)
+                if is_plot_function_deprecated
+                else sklearn.metrics.plot_confusion_matrix(*args, **kwargs)
+            )
 
+    y_true_arg_name = "y" if is_plot_function_deprecated else "y_true"
     classifier_artifacts = [
         _SklearnArtifact(
             name=prefix + "confusion_matrix",
@@ -319,10 +326,10 @@ def plot_confusion_matrix(*args, **kwargs):
             arguments=dict(
                 estimator=fitted_estimator,
                 X=X,
-                y_true=y_true,
                 sample_weight=sample_weight,
                 normalize="true",
                 cmap="Blues",
+                **{y_true_arg_name: y_true},
             ),
             title="Normalized confusion matrix",
         ),
@@ -335,7 +342,9 @@ def plot_confusion_matrix(*args, **kwargs):
             [
                 _SklearnArtifact(
                     name=prefix + "roc_curve",
-                    function=sklearn.metrics.plot_roc_curve,
+                    function=sklearn.metrics.RocCurveDisplay.from_estimator
+                    if is_plot_function_deprecated
+                    else sklearn.metrics.plot_roc_curve,
                     arguments=dict(
                         estimator=fitted_estimator,
                         X=X,
@@ -346,7 +355,9 @@ def plot_confusion_matrix(*args, **kwargs):
                 ),
                 _SklearnArtifact(
                     name=prefix + "precision_recall_curve",
-                    function=sklearn.metrics.plot_precision_recall_curve,
+                    function=sklearn.metrics.PrecisionRecallDisplay.from_estimator
+                    if is_plot_function_deprecated
+                    else sklearn.metrics.plot_precision_recall_curve,
                     arguments=dict(
                         estimator=fitted_estimator,
                         X=X,


Test patch: