.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/02_pipeline_with_scaler.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_02_pipeline_with_scaler.py: Inside a scikit-learn pipeline ============================== Use SoftDecisionTree inside a scikit-learn Pipeline with StandardScaler, and report 5-fold cross-validated accuracy on the Wine dataset. Scaling matters here: the sigmoid gates saturate when raw feature scales differ by orders of magnitude, as they do in Wine. Run with: python examples/02_pipeline_with_scaler.py .. GENERATED FROM PYTHON SOURCE LINES 14-32 .. rst-class:: sphx-glr-script-out .. code-block:: none Fold accuracies: [np.float64(0.972), np.float64(0.972), np.float64(0.972), np.float64(1.0), np.float64(0.971)] Mean accuracy: 0.978 (+/- 0.011) | .. code-block:: Python from sklearn.datasets import load_wine from sklearn.model_selection import cross_val_score from sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler from neural_trees import SoftDecisionTree X, y = load_wine(return_X_y=True) pipe = Pipeline([ ("scaler", StandardScaler()), ("model", SoftDecisionTree(depth=4, max_epochs=60, random_state=42)), ]) scores = cross_val_score(pipe, X, y, cv=5) print(f"Fold accuracies: {[round(s, 3) for s in scores]}") print(f"Mean accuracy: {scores.mean():.3f} (+/- {scores.std():.3f})") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.885 seconds) .. _sphx_glr_download_auto_examples_02_pipeline_with_scaler.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02_pipeline_with_scaler.ipynb <02_pipeline_with_scaler.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02_pipeline_with_scaler.py <02_pipeline_with_scaler.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 02_pipeline_with_scaler.zip <02_pipeline_with_scaler.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_