.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/basic.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_tutorials_basic.py: Creating a basic project ======================== In this tutorial, we will demonstrate how you can create a project and log a single experiment. .. GENERATED FROM PYTHON SOURCE LINES 8-17 .. code-block:: Python import json import pandas as pd from sklearn.datasets import make_classification from sklearn.svm import SVC from lazyscribe import Project .. GENERATED FROM PYTHON SOURCE LINES 18-19 First, let's create some toy data for the experiment. .. GENERATED FROM PYTHON SOURCE LINES 19-22 .. code-block:: Python X, y = make_classification(n_samples=1000, n_features=10) .. GENERATED FROM PYTHON SOURCE LINES 23-24 Next, create the project and run the model fit .. GENERATED FROM PYTHON SOURCE LINES 24-32 .. code-block:: Python project = Project(fpath="project.json", author="The Best") with project.log(name="Base performance") as exp: model = SVC(kernel="linear") model.fit(X, y) exp.log_metric("score", model.score(X, y)) exp.log_parameter("features", list(range(10))) .. GENERATED FROM PYTHON SOURCE LINES 33-34 Finally, let's print and view the experiment data. .. GENERATED FROM PYTHON SOURCE LINES 34-37 .. code-block:: Python print(json.dumps(list(project), indent=4, sort_keys=True)) .. rst-class:: sphx-glr-script-out .. code-block:: none [ { "artifacts": [], "author": "The Best", "created_at": "2025-03-14T14:41:13", "dependencies": [], "last_updated": "2025-03-14T14:41:13", "last_updated_by": "The Best", "metrics": { "score": 0.885 }, "name": "Base performance", "parameters": { "features": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] }, "short_slug": "base-performance", "slug": "base-performance-20250314144113", "tags": [], "tests": [] } ] .. GENERATED FROM PYTHON SOURCE LINES 38-39 You can also represent the project in a table: .. GENERATED FROM PYTHON SOURCE LINES 39-46 .. code-block:: Python experiments, tests = project.to_tabular() df = pd.DataFrame(experiments) df.columns = pd.MultiIndex.from_tuples(df.columns) df.head() .. raw:: html
name slug short_slug author created_at last_updated last_updated_by metrics
score
0 Base performance base-performance-20250314144113 base-performance The Best 2025-03-14T14:41:13 2025-03-14T14:41:13 The Best 0.885


.. GENERATED FROM PYTHON SOURCE LINES 47-48 Then, you can call :py:meth:`lazyscribe.Project.save` to save the output JSON. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.075 seconds) .. _sphx_glr_download_tutorials_basic.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: basic.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: basic.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: basic.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_