.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/getting_started/plot_quick_start.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_getting_started_plot_quick_start.py: .. _example_quick_start: =========== Quick start =========== .. GENERATED FROM PYTHON SOURCE LINES 10-14 Machine learning evaluation and diagnostics =========================================== Evaluate your model using skore's :class:`~skore.EstimatorReport`: .. GENERATED FROM PYTHON SOURCE LINES 16-29 .. code-block:: Python from sklearn.datasets import make_classification from sklearn.linear_model import LogisticRegression from sklearn.model_selection import train_test_split from skore import EstimatorReport X, y = make_classification(n_classes=2, n_samples=20_000, n_informative=4) X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0) log_report = EstimatorReport( LogisticRegression(), X_train=X_train, X_test=X_test, y_train=y_train, y_test=y_test ) .. GENERATED FROM PYTHON SOURCE LINES 30-32 Display the help tree to see all the insights that are available to you (skore detected that you are doing binary classification): .. GENERATED FROM PYTHON SOURCE LINES 34-36 .. code-block:: Python log_report.help() .. rst-class:: sphx-glr-script-out .. code-block:: none ╭─────────────────── Tools to diagnose estimator LogisticRegression ───────────────────╮ │ EstimatorReport │ │ ├── .metrics │ │ │ ├── .accuracy(...) (↗︎) - Compute the accuracy score. │ │ │ ├── .brier_score(...) (↘︎) - Compute the Brier score. │ │ │ ├── .confusion_matrix(...) - Plot the confusion matrix. │ │ │ ├── .log_loss(...) (↘︎) - Compute the log loss. │ │ │ ├── .precision(...) (↗︎) - Compute the precision score. │ │ │ ├── .precision_recall(...) - Plot the precision-recall curve. │ │ │ ├── .recall(...) (↗︎) - Compute the recall score. │ │ │ ├── .roc(...) - Plot the ROC curve. │ │ │ ├── .roc_auc(...) (↗︎) - Compute the ROC AUC score. │ │ │ ├── .timings(...) - Get all measured processing times related │ │ │ │ to the estimator. │ │ │ ├── .custom_metric(...) - Compute a custom metric. │ │ │ └── .report_metrics(...) - Report a set of metrics for our estimator. │ │ ├── .feature_importance │ │ │ ├── .coefficients(...) - Retrieve the coefficients of a linear │ │ │ │ model, including the intercept. │ │ │ └── .permutation(...) - Report the permutation feature importance. │ │ ├── .cache_predictions(...) - Cache estimator's predictions. │ │ ├── .clear_cache(...) - Clear the cache. │ │ ├── .get_predictions(...) - Get estimator's predictions. │ │ └── Attributes │ │ ├── .X_test - Testing data │ │ ├── .X_train - Training data │ │ ├── .y_test - Testing target │ │ ├── .y_train - Training target │ │ ├── .estimator_ - The cloned or copied estimator │ │ ├── .estimator_name_ - The name of the estimator │ │ ├── .fit_time_ - The time taken to fit the estimator, in │ │ │ seconds │ │ └── .ml_task - No description available │ │ │ │ │ │ Legend: │ │ (↗︎) higher is better (↘︎) lower is better │ ╰──────────────────────────────────────────────────────────────────────────────────────╯ .. GENERATED FROM PYTHON SOURCE LINES 37-38 Display the report metrics that was computed for you: .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: Python df_report_metrics = log_report.metrics.report_metrics(pos_label=1) df_report_metrics .. raw:: html
LogisticRegression
Metric
Precision 0.815981
Recall 0.805899
ROC AUC 0.895035
Brier score 0.131878
Fit time (s) 0.010845
Predict time (s) 0.000488


.. GENERATED FROM PYTHON SOURCE LINES 44-45 Display the ROC curve that was generated for you: .. GENERATED FROM PYTHON SOURCE LINES 47-50 .. code-block:: Python roc_plot = log_report.metrics.roc() roc_plot.plot() .. image-sg:: /auto_examples/getting_started/images/sphx_glr_plot_quick_start_001.png :alt: plot quick start :srcset: /auto_examples/getting_started/images/sphx_glr_plot_quick_start_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 51-53 Skore project: storing some items ================================= .. GENERATED FROM PYTHON SOURCE LINES 55-56 From your Python code, create and load a skore :class:`~skore.Project`: .. GENERATED FROM PYTHON SOURCE LINES 58-62 .. code-block:: Python import skore my_project = skore.Project("my_project") .. GENERATED FROM PYTHON SOURCE LINES 70-72 This will create a skore project directory named ``my_project.skore`` in your current working directory. .. GENERATED FROM PYTHON SOURCE LINES 74-75 Store some previous results in the skore project for safe-keeping: .. GENERATED FROM PYTHON SOURCE LINES 77-79 .. code-block:: Python my_project.put("log_report", log_report) .. GENERATED FROM PYTHON SOURCE LINES 80-81 Let us store a second model: .. GENERATED FROM PYTHON SOURCE LINES 83-94 .. code-block:: Python from sklearn.ensemble import RandomForestClassifier rf_report = EstimatorReport( RandomForestClassifier(), X_train=X_train, X_test=X_test, y_train=y_train, y_test=y_test, ) my_project.put("rf_report", rf_report) .. GENERATED FROM PYTHON SOURCE LINES 95-96 Now, let us retrieve the data that we previously stored: .. GENERATED FROM PYTHON SOURCE LINES 98-101 .. code-block:: Python metadata = my_project.reports.metadata() print(type(metadata)) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 102-103 We can perform some queries on our stored data: .. GENERATED FROM PYTHON SOURCE LINES 105-110 .. code-block:: Python from pprint import pprint report_get = metadata.query("ml_task.str.contains('classification')").reports() pprint(report_get) .. rst-class:: sphx-glr-script-out .. code-block:: none [EstimatorReport(estimator=LogisticRegression(), ...), EstimatorReport(estimator=RandomForestClassifier(), ...)] .. GENERATED FROM PYTHON SOURCE LINES 111-112 For example, we can retrieve the report metrics from the first estimator report: .. GENERATED FROM PYTHON SOURCE LINES 114-118 .. code-block:: Python report_get[0].metrics.report_metrics(pos_label=1) .. raw:: html
LogisticRegression
Metric
Precision 0.815981
Recall 0.805899
ROC AUC 0.895035
Brier score 0.131878
Fit time (s) 0.010845
Predict time (s) 0.000363


.. GENERATED FROM PYTHON SOURCE LINES 122-129 .. note:: If rendered in a Jupyter notebook, ``metadata`` would render an interactive parallel coordinate plot to search for your preferred model based on some metrics. Here is a screenshot: .. image:: /_static/images/screenshot_quick_start.png :alt: Screenshot of the widget in a Jupyter notebook .. GENERATED FROM PYTHON SOURCE LINES 131-134 .. seealso:: For a more in-depth guide, see our :ref:`example_skore_getting_started` page! .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 7.555 seconds) .. _sphx_glr_download_auto_examples_getting_started_plot_quick_start.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_quick_start.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_quick_start.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_quick_start.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_