.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/technical_details/plot_skore_api.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_technical_details_plot_skore_api.py: .. _example_skore_api: ============= The skore API ============= This example illustrates the consistent API shared by skore reports and displays. Reports expose the same accessors (``data``, ``metrics``, ``inspection``), and each method that produces a visualization returns a **Display** object. All displays implement a common interface: ``plot()``, ``frame()``, ``set_style()``, and ``help()``. .. GENERATED FROM PYTHON SOURCE LINES 16-32 Reports share the same accessor structure ========================================= :class:`~skore.EstimatorReport`, :class:`~skore.CrossValidationReport`, and :class:`~skore.ComparisonReport` all expose the same accessors where applicable: - **data**: dataset analysis - **metrics**: performance metrics and related displays (e.g. ROC, confusion matrix) - **inspection**: model inspection (e.g. coefficients, feature importance) The ``data`` accessor is only available on :class:`~skore.EstimatorReport` and :class:`~skore.CrossValidationReport` because when comparing models, the input data can be different and thus one can access the underlying reports to inspect the data. Calling a method on these accessors returns a **Display** object. The same pattern holds across report types, so once you know one, you know them all. .. GENERATED FROM PYTHON SOURCE LINES 34-39 Minimal setup: one report and one display ========================================= We build a simple :class:`~skore.EstimatorReport` and use it to show how accessors return displays and how those displays behave. .. GENERATED FROM PYTHON SOURCE LINES 39-50 .. code-block:: Python from sklearn.datasets import load_breast_cancer from sklearn.linear_model import LogisticRegression from skore import EstimatorReport, train_test_split from skrub import tabular_pipeline X, y = load_breast_cancer(return_X_y=True, as_frame=True) split_data = train_test_split(X=X, y=y, random_state=42, as_dict=True) estimator = tabular_pipeline(LogisticRegression()) report = EstimatorReport(estimator, **split_data) .. rst-class:: sphx-glr-script-out .. code-block:: none ╭────────────────────── HighClassImbalanceTooFewExamplesWarning ───────────────────────╮ │ It seems that you have a classification problem with at least one class with fewer │ │ than 100 examples in the test set. In this case, using train_test_split may not be a │ │ good idea because of high variability in the scores obtained on the test set. We │ │ suggest three options to tackle this challenge: you can increase test_size, collect │ │ more data, or use skore's CrossValidationReport with the `splitter` parameter of │ │ your choice. │ ╰──────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────── ShuffleTrueWarning ─────────────────────────────────╮ │ We detected that the `shuffle` parameter is set to `True` either explicitly or from │ │ its default value. In case of time-ordered events (even if they are independent), │ │ this will result in inflated model performance evaluation because natural drift will │ │ not be taken into account. We recommend setting the shuffle parameter to `False` in │ │ order to ensure the evaluation process is really representative of your production │ │ release process. │ ╰──────────────────────────────────────────────────────────────────────────────────────╯ .. GENERATED FROM PYTHON SOURCE LINES 51-56 Data accessor: ``report.data.analyze()`` returns a display ---------------------------------------------------------- The **data** accessor provides dataset summaries. Its ``analyze()`` method returns a :class:`~skore._sklearn._plot.data.table_report.TableReportDisplay`. .. GENERATED FROM PYTHON SOURCE LINES 56-59 .. code-block:: Python data_display = report.data.analyze() data_display.help() .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 60-63 Every display implements the same API. You can: - **Plot** it (with optional backend and style): .. GENERATED FROM PYTHON SOURCE LINES 63-65 .. code-block:: Python data_display.plot(kind="dist", x="mean radius", y="mean texture") .. image-sg:: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_001.png :alt: plot skore api :srcset: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 66-67 You can set the style of the plot via ``set_style()`` and then call ``plot()``: .. GENERATED FROM PYTHON SOURCE LINES 67-70 .. code-block:: Python data_display.set_style(scatterplot_kwargs={"color": "orange", "alpha": 1.0}) data_display.plot(kind="dist", x="mean radius", y="mean texture") .. image-sg:: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_002.png :alt: plot skore api :srcset: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 71-72 - **Export** the underlying data as a DataFrame: .. GENERATED FROM PYTHON SOURCE LINES 72-74 .. code-block:: Python data_display.frame() .. raw:: html
mean radius mean texture mean perimeter mean area mean smoothness mean compactness mean concavity mean concave points mean symmetry mean fractal dimension radius error texture error perimeter error area error smoothness error compactness error concavity error concave points error symmetry error fractal dimension error worst radius worst texture worst perimeter worst area worst smoothness worst compactness worst concavity worst concave points worst symmetry worst fractal dimension target
0 12.89 13.12 81.89 515.9 0.06955 0.03729 0.02260 0.01171 0.1337 0.05581 0.1532 0.4690 1.115 12.68 0.004731 0.013450 0.016520 0.005905 0.01619 0.002081 13.62 15.54 87.40 577.0 0.09616 0.1147 0.11860 0.05366 0.2309 0.06915 1
1 13.40 20.52 88.64 556.7 0.11060 0.14690 0.14450 0.08172 0.2116 0.07325 0.3906 0.9306 3.093 33.67 0.005414 0.022650 0.034520 0.013340 0.01705 0.004005 16.41 29.66 113.30 844.4 0.15740 0.3856 0.51060 0.20510 0.3585 0.11090 0
2 12.96 18.29 84.18 525.2 0.07351 0.07899 0.04057 0.01883 0.1874 0.05899 0.2357 1.2990 2.397 20.21 0.003629 0.037130 0.034520 0.010650 0.02632 0.003705 14.13 24.61 96.31 621.9 0.09329 0.2318 0.16040 0.06608 0.3207 0.07247 1
3 17.75 28.03 117.30 981.6 0.09997 0.13140 0.16980 0.08293 0.1713 0.05916 0.3897 1.0770 2.873 43.95 0.004714 0.020150 0.036970 0.011100 0.01237 0.002556 21.53 38.54 145.40 1437.0 0.14010 0.3762 0.63990 0.19700 0.2972 0.09075 0
4 20.58 22.14 134.70 1290.0 0.09090 0.13480 0.16400 0.09561 0.1765 0.05024 0.8601 1.4800 7.029 111.70 0.008124 0.036110 0.054890 0.027650 0.03176 0.002365 23.24 27.84 158.30 1656.0 0.11780 0.2920 0.38610 0.19200 0.2909 0.05865 0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
564 14.64 15.24 95.77 651.9 0.11320 0.13390 0.09966 0.07064 0.2116 0.06346 0.5115 0.7372 3.814 42.76 0.005508 0.044120 0.044360 0.016230 0.02427 0.004841 16.34 18.24 109.40 803.6 0.12770 0.3089 0.26040 0.13970 0.3151 0.08473 1
565 14.45 20.22 94.49 642.7 0.09872 0.12060 0.11800 0.05980 0.1950 0.06466 0.2092 0.6509 1.446 19.42 0.004044 0.015970 0.020000 0.007303 0.01522 0.001976 18.33 30.12 117.90 1044.0 0.15520 0.4056 0.49670 0.18380 0.4753 0.10130 0
566 11.04 16.83 70.92 373.2 0.10770 0.07804 0.03046 0.02480 0.1714 0.06340 0.1967 1.3870 1.342 13.54 0.005158 0.009355 0.010560 0.007483 0.01718 0.002198 12.41 26.44 79.93 471.4 0.13690 0.1482 0.10670 0.07431 0.2998 0.07881 1
567 19.81 22.15 130.00 1260.0 0.09831 0.10270 0.14790 0.09498 0.1582 0.05395 0.7582 1.0170 5.865 112.40 0.006494 0.018930 0.033910 0.015210 0.01356 0.001997 27.32 30.88 186.80 2398.0 0.15120 0.3150 0.53720 0.23880 0.2768 0.07615 0
568 10.26 12.22 65.75 321.6 0.09996 0.07542 0.01923 0.01968 0.1800 0.06569 0.1911 0.5477 1.348 11.88 0.005682 0.013650 0.008496 0.006929 0.01938 0.002371 11.38 15.65 73.23 394.5 0.13430 0.1650 0.08615 0.06696 0.2937 0.07722 1

569 rows × 31 columns



.. GENERATED FROM PYTHON SOURCE LINES 75-82 Metrics accessor: same idea, same display API ============================================= The **metrics** accessor exposes methods such as ``confusion_matrix()``, ``roc_curve()``, ``precision_recall()``, and ``prediction_error()``. Each returns a display (e.g. :class:`~skore.ConfusionMatrixDisplay`) with the same interface: ``plot()``, ``frame()``, ``set_style()``, ``help()``. .. GENERATED FROM PYTHON SOURCE LINES 82-85 .. code-block:: Python metrics_display = report.metrics.confusion_matrix() metrics_display.help() .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 86-88 .. code-block:: Python metrics_display.frame() .. raw:: html
true_label predicted_label value threshold split estimator data_source
356 0 0 53 0.527467 None LogisticRegression test
357 0 1 1 0.527467 None LogisticRegression test
358 1 0 0 0.527467 None LogisticRegression test
359 1 1 89 0.527467 None LogisticRegression test


.. GENERATED FROM PYTHON SOURCE LINES 89-90 Draw the confusion matrix by calling ``plot()``: .. GENERATED FROM PYTHON SOURCE LINES 90-92 .. code-block:: Python metrics_display.plot() .. image-sg:: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_003.png :alt: Confusion Matrix Decision threshold: 0.50 Data source: Test set :srcset: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 93-100 Inspection accessor =================== The **inspection** accessor exposes model-specific displays (e.g. ``coefficients()`` for linear models, ``impurity_decrease()`` for trees). These also return Display objects with the same ``plot()``, ``frame()``, ``set_style()``, and ``help()`` methods. .. GENERATED FROM PYTHON SOURCE LINES 100-103 .. code-block:: Python inspection_display = report.inspection.coefficients() inspection_display.plot(select_k=15, sorting_order="descending") .. image-sg:: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_004.png :alt: Coefficients of LogisticRegression :srcset: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 104-109 Same API with :class:`~skore.CrossValidationReport` =================================================== The same accessors and display API apply to :class:`~skore.CrossValidationReport`. We use the same dataset and model; only the report type changes. .. GENERATED FROM PYTHON SOURCE LINES 109-113 .. code-block:: Python from skore import CrossValidationReport cv_report = CrossValidationReport(estimator, X, y, splitter=3) .. GENERATED FROM PYTHON SOURCE LINES 114-116 Again: ``data``, ``metrics``, and ``inspection`` return displays with ``plot()``, ``frame()``, and ``set_style()``. .. GENERATED FROM PYTHON SOURCE LINES 116-118 .. code-block:: Python cv_report.data.analyze().plot(kind="dist", x="mean radius", y="mean texture") .. image-sg:: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_005.png :alt: plot skore api :srcset: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 119-121 .. code-block:: Python cv_report.metrics.confusion_matrix().plot() .. image-sg:: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_006.png :alt: Confusion Matrix Decision threshold: 0.50 Data source: Test set :srcset: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 122-124 .. code-block:: Python cv_report.inspection.coefficients().plot(select_k=10, sorting_order="descending") .. image-sg:: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_007.png :alt: Coefficients of LogisticRegression :srcset: /auto_examples/technical_details/images/sphx_glr_plot_skore_api_007.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 125-127 The same accessors and display API apply to :class:`~skore.ComparisonReport` (metrics and inspection; no data accessor when comparing reports). .. GENERATED FROM PYTHON SOURCE LINES 129-146 Summary ======= - **Reports** (Estimator, CrossValidation, Comparison) use the same accessor layout: ``report.data``, ``report.metrics``, ``report.inspection`` (where applicable). - **Accessor methods** that produce figures or tables return **Display** objects. - **Displays** share a single, predictable API: - ``plot(**kwargs)`` — render the visualization - ``frame(**kwargs)`` — return the data as a :class:`pandas.DataFrame` - ``set_style(policy=..., **kwargs)`` — customize appearance - ``help()`` — show available options This consistency makes it easy to switch between report types and to reuse the same workflow across data, metrics, and inspection. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.267 seconds) .. _sphx_glr_download_auto_examples_technical_details_plot_skore_api.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_skore_api.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_skore_api.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_skore_api.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_