|
| 1 | +""" |
| 2 | +================================= |
| 3 | +1) Getting started with ``skore`` |
| 4 | +================================= |
| 5 | +
|
| 6 | +This example runs the :ref:`getting_started` guide. |
| 7 | +
|
| 8 | +``skore`` UI |
| 9 | +------------ |
| 10 | +
|
| 11 | +This section provides a quick start to the ``skore`` UI, an open-source package that aims to enable data scientists to: |
| 12 | +
|
| 13 | +#. Store objects of different types from their Python code: python lists, ``scikit-learn`` fitted pipelines, ``plotly`` figures, and more. |
| 14 | +#. Track and visualize these stored objects on a user-friendly dashboard. |
| 15 | +#. Export the dashboard to a HTML file. |
| 16 | +
|
| 17 | +Initialize a Project and launch the UI |
| 18 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 19 | +
|
| 20 | +From your shell, initialize a skore project, here named ``my_project_gs``, that |
| 21 | +will be in your current working directory: |
| 22 | +""" |
| 23 | + |
| 24 | +# %% |
| 25 | +import subprocess |
| 26 | + |
| 27 | +# remove the project if it already exists |
| 28 | +subprocess.run("rm -rf my_project_gs.skore".split()) |
| 29 | + |
| 30 | +# create the project |
| 31 | +subprocess.run("python3 -m skore create my_project_gs".split()) |
| 32 | + |
| 33 | +# %% |
| 34 | +# This will create a ``skore`` project directory named ``my_project_gs`` in the |
| 35 | +# current directory. |
| 36 | +# |
| 37 | +# From your shell (in the same directory), start the UI locally: |
| 38 | +# |
| 39 | +# .. code:: console |
| 40 | +# |
| 41 | +# python -m skore launch "my_project_gs" |
| 42 | +# |
| 43 | +# This will automatically open a browser at the UI's location. |
| 44 | +# |
| 45 | +# Now that the project file exists, we can load it in our notebook so that we can |
| 46 | +# read from and write to it: |
| 47 | + |
| 48 | +# %% |
| 49 | +from skore import load |
| 50 | + |
| 51 | +my_project_gs = load("my_project_gs.skore") |
| 52 | + |
| 53 | +# %% |
| 54 | +# Storing some items |
| 55 | +# ^^^^^^^^^^^^^^^^^^ |
| 56 | +# |
| 57 | +# Storing an integer: |
| 58 | + |
| 59 | +# %% |
| 60 | +my_project_gs.put("my_int", 3) |
| 61 | + |
| 62 | +# %% |
| 63 | +# Here, the name of my stored item is ``my_int`` and the integer value is 3. |
| 64 | + |
| 65 | +# %% |
| 66 | +my_project_gs.get("my_int") |
| 67 | + |
| 68 | +# %% |
| 69 | +# For a ``pandas`` data frame: |
| 70 | + |
| 71 | +# %% |
| 72 | +import numpy as np |
| 73 | +import pandas as pd |
| 74 | + |
| 75 | +my_df = pd.DataFrame(np.random.randn(3, 3)) |
| 76 | + |
| 77 | +my_project_gs.put("my_df", my_df) |
| 78 | + |
| 79 | +# %% |
| 80 | +my_project_gs.get("my_df") |
| 81 | + |
| 82 | +# %% |
| 83 | +# For a ``matplotlib`` figure: |
| 84 | + |
| 85 | +# %% |
| 86 | +import matplotlib.pyplot as plt |
| 87 | + |
| 88 | +x = [0, 1, 2, 3, 4, 5] |
| 89 | +fig, ax = plt.subplots(figsize=(5, 3), layout="constrained") |
| 90 | +_ = ax.plot(x) |
| 91 | + |
| 92 | +my_project_gs.put("my_figure", fig) |
| 93 | + |
| 94 | +# %% |
| 95 | +# For a ``scikit-learn`` fitted pipeline: |
| 96 | + |
| 97 | +# %% |
| 98 | +from sklearn.datasets import load_diabetes |
| 99 | +from sklearn.linear_model import Lasso |
| 100 | +from sklearn.pipeline import Pipeline |
| 101 | +from sklearn.preprocessing import StandardScaler |
| 102 | + |
| 103 | +diabetes = load_diabetes() |
| 104 | +X = diabetes.data[:150] |
| 105 | +y = diabetes.target[:150] |
| 106 | +my_pipeline = Pipeline( |
| 107 | + [("standard_scaler", StandardScaler()), ("lasso", Lasso(alpha=2))] |
| 108 | +) |
| 109 | +my_pipeline.fit(X, y) |
| 110 | + |
| 111 | +my_project_gs.put("my_fitted_pipeline", my_pipeline) |
| 112 | + |
| 113 | +# %% |
| 114 | +my_project_gs.get("my_fitted_pipeline") |
| 115 | + |
| 116 | +# %% |
| 117 | +# Back to the dashboard |
| 118 | +# ^^^^^^^^^^^^^^^^^^^^^ |
| 119 | +# |
| 120 | +# #. On the top left, create a new ``View``. |
| 121 | +# #. From the ``Elements`` section on the bottom left, you can add stored items to this view, either by double-cliking on them or by doing drag-and-drop. |
| 122 | +# |
| 123 | +# .. image:: https://raw.githubusercontent.com/sylvaincom/sylvaincom.github.io/master/files/probabl/skore/2024_10_14_skore_demo.gif |
| 124 | +# :alt: Getting started with ``skore`` demo |
0 commit comments