.. 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 <sphx_glr_download_tutorials_basic.py>`
        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

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead tr th {
            text-align: left;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr>
          <th></th>
          <th>name</th>
          <th>slug</th>
          <th>short_slug</th>
          <th>author</th>
          <th>created_at</th>
          <th>last_updated</th>
          <th>last_updated_by</th>
          <th>metrics</th>
        </tr>
        <tr>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th>score</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>Base performance</td>
          <td>base-performance-20250314144113</td>
          <td>base-performance</td>
          <td>The Best</td>
          <td>2025-03-14T14:41:13</td>
          <td>2025-03-14T14:41:13</td>
          <td>The Best</td>
          <td>0.885</td>
        </tr>
      </tbody>
    </table>
    </div>
    </div>
    <br />
    <br />

.. 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 <basic.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: basic.py <basic.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: basic.zip <basic.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_