From 066e14beac155f8e5a87e797191e44e70262043a Mon Sep 17 00:00:00 2001 From: Marie Sacksick <79304610+MarieS-WiMLDS@users.noreply.github.com> Date: Fri, 31 Jan 2025 10:28:15 +0100 Subject: [PATCH] chore: Remove cv reporter (#1265) Now that we have the CV Report, and that the CV Reporter has been announced as deprecated in the previous version, we can drop the CV Reporter. --- README.md | 2 +- .../model_evaluation/plot_cross_validate.py | 167 --------- .../src/components/CrossValidationReport.vue | 34 -- .../CrossValidationReportDetails.vue | 96 ------ .../components/CrossValidationReportPlots.vue | 69 ---- .../CrossValidationReportResults.vue | 326 ------------------ .../src/components/MediaWidgetSelector.vue | 1 - skore-ui/src/views/ComponentsView.vue | 1 - skore/src/skore/__init__.py | 2 - skore/src/skore/persistence/item/__init__.py | 5 - .../item/cross_validation_reporter_item.py | 306 ---------------- skore/src/skore/sklearn/__init__.py | 2 - .../sklearn/cross_validation/__init__.py | 7 - .../cross_validation_helpers.py | 178 ---------- .../cross_validation_reporter.py | 202 ----------- .../cross_validation/plots/__init__.py | 1 - .../plots/compare_scores_plot.py | 116 ------- .../cross_validation/plots/timing_plot.py | 123 ------- .../sklearn/test_cross_validate.py | 260 -------------- skore/tests/integration/ui/test_ui.py | 161 +-------- .../test_cross_validation_reporter_item.py | 206 ----------- .../tests/unit/sklearn/test_cross_validate.py | 98 ------ sphinx/api.rst | 2 - 23 files changed, 3 insertions(+), 2362 deletions(-) delete mode 100644 examples/model_evaluation/plot_cross_validate.py delete mode 100644 skore-ui/src/components/CrossValidationReport.vue delete mode 100644 skore-ui/src/components/CrossValidationReportDetails.vue delete mode 100644 skore-ui/src/components/CrossValidationReportPlots.vue delete mode 100644 skore-ui/src/components/CrossValidationReportResults.vue delete mode 100644 skore/src/skore/persistence/item/cross_validation_reporter_item.py delete mode 100644 skore/src/skore/sklearn/cross_validation/__init__.py delete mode 100644 skore/src/skore/sklearn/cross_validation/cross_validation_helpers.py delete mode 100644 skore/src/skore/sklearn/cross_validation/cross_validation_reporter.py delete mode 100644 skore/src/skore/sklearn/cross_validation/plots/__init__.py delete mode 100644 skore/src/skore/sklearn/cross_validation/plots/compare_scores_plot.py delete mode 100644 skore/src/skore/sklearn/cross_validation/plots/timing_plot.py delete mode 100644 skore/tests/integration/sklearn/test_cross_validate.py delete mode 100644 skore/tests/unit/item/test_cross_validation_reporter_item.py delete mode 100644 skore/tests/unit/sklearn/test_cross_validate.py diff --git a/README.md b/README.md index b0f05e495..b9a811c2a 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ You can find information on the latest version [here](https://anaconda.org/conda ``` This will create a skore project directory named `my_project.skore` in your current working directory. -2. Evaluate your model using `skore.CrossValidationReporter`: +2. Evaluate your model using `skore.CrossValidationReport`: ```python from sklearn.datasets import make_classification from sklearn.linear_model import LogisticRegression diff --git a/examples/model_evaluation/plot_cross_validate.py b/examples/model_evaluation/plot_cross_validate.py deleted file mode 100644 index 8a15bbda5..000000000 --- a/examples/model_evaluation/plot_cross_validate.py +++ /dev/null @@ -1,167 +0,0 @@ -""" -.. _example_cross_validate: - -================ -Cross-validation -================ - -This example illustrates the motivation and the use of skore's -:class:`skore.CrossValidationReporter` to get assistance when developing ML/DS projects. - -.. warning :: - - **Deprecation Notice**: - :class:`skore.CrossValidationReporter` is deprecated in favor of :class:`skore.CrossValidationReport`. -""" - -# %% -# Creating and loading the skore project -# ====================================== - -# %% -# We create and load the skore project from the current directory: -import skore - -# sphinx_gallery_start_ignore -import os -import tempfile -from pathlib import Path - -temp_dir = tempfile.TemporaryDirectory() -temp_dir_path = Path(temp_dir.name) -os.chdir(temp_dir_path) -# sphinx_gallery_end_ignore -my_project = skore.Project("my_project") - - -# %% -# Cross-validation in scikit-learn -# ================================ -# -# Scikit-learn holds two functions for cross-validation: -# -# * :func:`sklearn.model_selection.cross_val_score` -# * :func:`sklearn.model_selection.cross_validate` -# -# Essentially, :func:`sklearn.model_selection.cross_val_score` runs cross-validation for -# single metric evaluation, while :func:`sklearn.model_selection.cross_validate` runs -# cross-validation with multiple metrics and can also return extra information such as -# train scores, fit times, and score times. -# -# Hence, in skore, we are more interested in the -# :func:`sklearn.model_selection.cross_validate` function as it allows to do -# more than the historical :func:`sklearn.model_selection.cross_val_score`. -# -# Let us illustrate cross-validation on a multi-class classification task. - -# %% -from sklearn.datasets import load_iris -from sklearn.svm import SVC - -X, y = load_iris(return_X_y=True) -clf = SVC(kernel="linear", C=1, random_state=0) - -# %% -# Single metric evaluation using :func:`sklearn.model_selection.cross_validate`: - -# %% -from sklearn.model_selection import cross_validate as sklearn_cross_validate - -cv_results = sklearn_cross_validate(clf, X, y, cv=5) -print(f"test_score: {cv_results['test_score']}") - -# %% -# Multiple metric evaluation using :func:`sklearn.model_selection.cross_validate`: - -# %% -import pandas as pd - -cv_results = sklearn_cross_validate( - clf, - X, - y, - cv=5, - scoring=["accuracy", "precision_macro"], -) -test_scores = pd.DataFrame(cv_results)[["test_accuracy", "test_precision_macro"]] -test_scores - -# %% -# In scikit-learn, why do we recommend using ``cross_validate`` over ``cross_val_score``? -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# Here, for the :class:`~sklearn.svm.SVC`, the default score is the accuracy. -# If the users want other scores to better understand their model such as the -# precision and the recall, they can specify it which is very convenient. -# Otherwise, they would have to run several -# :func:`sklearn.model_selection.cross_val_score` with different ``scoring`` -# parameters each time, which leads to more unnecessary compute. -# -# Why do we recommend using skore's ``CrossValidationReporter`` over scikit-learn's ``cross_validate``? -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# In the example above, what if the users ran scikit-learn's -# :func:`sklearn.model_selection.cross_validate` but forgot to manually add a -# crucial score for their use case such as the recall? -# They would have to re-run the whole cross-validation experiment by adding this -# crucial score, which leads to more compute. - -# %% -# Cross-validation in skore -# ========================= -# -# In order to assist its users when programming, skore has implemented a -# :class:`skore.CrossValidationReporter` class that wraps scikit-learn's -# :func:`sklearn.model_selection.cross_validate`, to provide more -# context and facilitate the analysis. -# -# Classification task -# ^^^^^^^^^^^^^^^^^^^ -# -# Let us continue with the same use case. - -# %% -reporter = skore.CrossValidationReporter(clf, X, y, cv=5) -reporter.plots.scores - -# %% -# Skore's :class:`~skore.CrossValidationReporter` advantages are the following: -# -# * By default, it computes several useful scores without the need to -# manually specify them. For classification, one can observe that it computed the -# accuracy, the precision, and the recall. -# -# * We automatically get some interactive Plotly graphs to better understand how our -# model behaves depending on the split. For example: -# -# * We can compare the fitting and scoring times together for each split. -# -# * Moreover, we can focus on the times per data points as the train and -# test splits usually have a different number of samples. -# -# * We can compare the accuracy, precision, and recall scores together for each -# split. - -# %% -# Regression task -# ^^^^^^^^^^^^^^^ - -# %% -from sklearn.datasets import load_diabetes -from sklearn.linear_model import Lasso - -X, y = load_diabetes(return_X_y=True) -lasso = Lasso() - -reporter = skore.CrossValidationReporter(lasso, X, y, cv=5) -reporter.plots.scores - -# %% -# We can put the reporter in the project, and retrieve it as is: -my_project.put("cross_validation_reporter", reporter) - -reporter = my_project.get("cross_validation_reporter") -reporter.plots.scores -# sphinx_gallery_start_ignore -temp_dir.cleanup() -# sphinx_gallery_end_ignore diff --git a/skore-ui/src/components/CrossValidationReport.vue b/skore-ui/src/components/CrossValidationReport.vue deleted file mode 100644 index a22ec1284..000000000 --- a/skore-ui/src/components/CrossValidationReport.vue +++ /dev/null @@ -1,34 +0,0 @@ - - - diff --git a/skore-ui/src/components/CrossValidationReportDetails.vue b/skore-ui/src/components/CrossValidationReportDetails.vue deleted file mode 100644 index afd3adf63..000000000 --- a/skore-ui/src/components/CrossValidationReportDetails.vue +++ /dev/null @@ -1,96 +0,0 @@ - - - - - diff --git a/skore-ui/src/components/CrossValidationReportPlots.vue b/skore-ui/src/components/CrossValidationReportPlots.vue deleted file mode 100644 index 3422c6815..000000000 --- a/skore-ui/src/components/CrossValidationReportPlots.vue +++ /dev/null @@ -1,69 +0,0 @@ - - - - - diff --git a/skore-ui/src/components/CrossValidationReportResults.vue b/skore-ui/src/components/CrossValidationReportResults.vue deleted file mode 100644 index 53b521ac0..000000000 --- a/skore-ui/src/components/CrossValidationReportResults.vue +++ /dev/null @@ -1,326 +0,0 @@ - - - - - diff --git a/skore-ui/src/components/MediaWidgetSelector.vue b/skore-ui/src/components/MediaWidgetSelector.vue index 90be72269..6ee9dcbe6 100644 --- a/skore-ui/src/components/MediaWidgetSelector.vue +++ b/skore-ui/src/components/MediaWidgetSelector.vue @@ -1,5 +1,4 @@