.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_iris_classification.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_01_iris_classification.py: Training a soft decision tree ============================= Minimal end-to-end example: train a Soft Decision Tree on Iris. Run with: python examples/01_iris_classification.py .. GENERATED FROM PYTHON SOURCE LINES 10-24 .. rst-class:: sphx-glr-script-out .. code-block:: none Test accuracy: 0.933 | .. code-block:: Python from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from neural_trees import SoftDecisionTree X, y = load_iris(return_X_y=True) X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.3, stratify=y, random_state=42 ) model = SoftDecisionTree(depth=4, max_epochs=40, random_state=42) model.fit(X_train, y_train) print(f"Test accuracy: {model.score(X_test, y_test):.3f}") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.234 seconds) .. _sphx_glr_download_auto_examples_01_iris_classification.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_iris_classification.ipynb <01_iris_classification.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_iris_classification.py <01_iris_classification.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 01_iris_classification.zip <01_iris_classification.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_