{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n\n# Local skore Project\n\nThis example shows how to use :class:`~skore.Project` in **local** mode: store\nreports on your machine and inspect them. A key point is that\n:meth:`~skore.Project.summarize` returns a ``Summary`` object that holds the\nmetadata and metrics of every report. In Jupyter it renders as an interactive\ntable with three views (Table, parallel-coordinates Plot, and Trend) where you\ncan filter and pick reports to build a query string; the underlying\n:class:`pandas.DataFrame` is accessible through its ``frame`` method.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Create a local project and store reports\n\nWe use a temporary directory as the workspace so the example is self-contained.\nIn practice you can omit ``workspace`` to use the default (e.g. a ``skore/``\ndirectory in your user cache).\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from pathlib import Path\nfrom tempfile import TemporaryDirectory\n\nfrom skore import Project\n\ntmp_dir = TemporaryDirectory()\ntmp_path = Path(tmp_dir.name)\nproject = Project(\"example-project\", workspace=tmp_path)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from sklearn.datasets import load_breast_cancer\nfrom sklearn.linear_model import LogisticRegression\nfrom skrub import tabular_pipeline\n\nX, y = load_breast_cancer(return_X_y=True, as_frame=True)\nestimator = tabular_pipeline(LogisticRegression(max_iter=1_000))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nfrom sklearn.base import clone\nfrom skore import evaluate\n\nfor regularization in np.logspace(-7, 7, 31):\n    report = evaluate(\n        clone(estimator).set_params(logisticregression__C=regularization),\n        X,\n        y,\n        splitter=0.2,\n        pos_label=1,\n    )\n    project.put(f\"lr-regularization-{regularization:.1e}\", report)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Summarize: you get a Summary\n\n:meth:`~skore.Project.summarize` returns a :class:`~skore.Summary` object. In a\nJupyter environment it renders as an interactive table where you can filter rows and\npick reports across the different views; the selection produces a query string ready\nto pass to :meth:`~skore.Summary.query`.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "summary = project.summarize()\nsummary"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Filter reports by metric (e.g. keep only those above a given accuracy) and\nwork with the result as a table.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "summary.query(\"log_loss < 0.1\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Use :meth:`~skore.Summary.compare` to load the corresponding reports from the\nproject (optionally after filtering the summary). Passing ``return_as=\"report\"``\nreturns a :class:`~skore.ComparisonReport` built from those reports.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "reports = summary.query(\"log_loss < 0.1\").compare(return_as=\"report\")\nreports"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "_ = reports.metrics.roc().plot(subplot_by=None)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "project.delete(\"example-project\", workspace=tmp_path)\ntmp_dir.cleanup()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.14.5"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}