.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/03_complex_models/run_stacked_models.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_03_complex_models_run_stacked_models.py: Stacking Classification ======================= This example uses the ``iris`` dataset and performs a complex stacking classification. We will use two different classifiers, one applied to petal features and one applied to sepal features. A final logistic regression classifier will be applied on the predictions of the two classifiers. .. include:: ../../links.inc .. GENERATED FROM PYTHON SOURCE LINES 12-20 .. code-block:: Python # Authors: Federico Raimondo # License: AGPL from seaborn import load_dataset from julearn import run_cross_validation from julearn.pipeline import PipelineCreator from julearn.utils import configure_logging .. GENERATED FROM PYTHON SOURCE LINES 21-22 Set the logging level to info to see extra information. .. GENERATED FROM PYTHON SOURCE LINES 22-24 .. code-block:: Python configure_logging(level="INFO") .. rst-class:: sphx-glr-script-out .. code-block:: none 2026-01-16 10:54:11,782 - julearn - INFO - ===== Lib Versions ===== 2026-01-16 10:54:11,782 - julearn - INFO - numpy: 1.26.4 2026-01-16 10:54:11,782 - julearn - INFO - scipy: 1.17.0 2026-01-16 10:54:11,782 - julearn - INFO - sklearn: 1.7.2 2026-01-16 10:54:11,782 - julearn - INFO - pandas: 2.3.3 2026-01-16 10:54:11,782 - julearn - INFO - julearn: 0.3.5.dev123 2026-01-16 10:54:11,782 - julearn - INFO - ======================== .. GENERATED FROM PYTHON SOURCE LINES 25-27 .. code-block:: Python df_iris = load_dataset("iris") .. GENERATED FROM PYTHON SOURCE LINES 28-30 The dataset has three kind of species. We will keep two to perform a binary classification. .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: Python df_iris = df_iris[df_iris["species"].isin(["versicolor", "virginica"])] .. GENERATED FROM PYTHON SOURCE LINES 33-35 As features, we will use the sepal length, width and petal length. We will try to predict the species. .. GENERATED FROM PYTHON SOURCE LINES 35-70 .. code-block:: Python X = ["sepal_length", "sepal_width", "petal_length", "petal_width"] y = "species" # Define our feature types X_types = { "sepal": ["sepal_length", "sepal_width"], "petal": ["petal_length", "petal_width"], } # Create the pipeline for the sepal features, by default will apply to "sepal" model_sepal = PipelineCreator(problem_type="classification", apply_to="sepal") model_sepal.add("filter_columns", apply_to="*", keep="sepal") model_sepal.add("zscore") model_sepal.add("svm") # Create the pipeline for the petal features, by default will apply to "petal" model_petal = PipelineCreator(problem_type="classification", apply_to="petal") model_petal.add("filter_columns", apply_to="*", keep="petal") model_petal.add("zscore") model_petal.add("rf") # Create the stacking model model = PipelineCreator(problem_type="classification") model.add( "stacking", estimators=[[("model_sepal", model_sepal), ("model_petal", model_petal)]], apply_to="*", ) scores = run_cross_validation( X=X, y=y, X_types=X_types, data=df_iris, model=model ) print(scores["test_score"]) .. rst-class:: sphx-glr-script-out .. code-block:: none 2026-01-16 10:54:11,785 - julearn - INFO - Adding step filter_columns that applies to ColumnTypes 2026-01-16 10:54:11,785 - julearn - INFO - Setting hyperparameter keep = sepal 2026-01-16 10:54:11,786 - julearn - INFO - Step added 2026-01-16 10:54:11,786 - julearn - INFO - Adding step zscore that applies to ColumnTypes 2026-01-16 10:54:11,786 - julearn - INFO - Step added 2026-01-16 10:54:11,786 - julearn - INFO - Adding step svm that applies to ColumnTypes 2026-01-16 10:54:11,786 - julearn - INFO - Step added 2026-01-16 10:54:11,787 - julearn - INFO - Adding step filter_columns that applies to ColumnTypes 2026-01-16 10:54:11,787 - julearn - INFO - Setting hyperparameter keep = petal 2026-01-16 10:54:11,787 - julearn - INFO - Step added 2026-01-16 10:54:11,787 - julearn - INFO - Adding step zscore that applies to ColumnTypes 2026-01-16 10:54:11,787 - julearn - INFO - Step added 2026-01-16 10:54:11,787 - julearn - INFO - Adding step rf that applies to ColumnTypes 2026-01-16 10:54:11,787 - julearn - INFO - Step added 2026-01-16 10:54:11,788 - julearn - INFO - Adding step stacking that applies to ColumnTypes 2026-01-16 10:54:11,788 - julearn - INFO - Setting hyperparameter estimators = [('model_sepal', ), ('model_petal', )] 2026-01-16 10:54:11,788 - julearn - INFO - Step added 2026-01-16 10:54:11,788 - julearn - INFO - ==== Input Data ==== 2026-01-16 10:54:11,788 - julearn - INFO - Using dataframe as input 2026-01-16 10:54:11,788 - julearn - INFO - Features: ['sepal_length', 'sepal_width', 'petal_length', 'petal_width'] 2026-01-16 10:54:11,788 - julearn - INFO - Target: species 2026-01-16 10:54:11,788 - julearn - INFO - Expanded features: ['sepal_length', 'sepal_width', 'petal_length', 'petal_width'] 2026-01-16 10:54:11,788 - julearn - INFO - X_types:{'sepal': ['sepal_length', 'sepal_width'], 'petal': ['petal_length', 'petal_width']} 2026-01-16 10:54:11,789 - julearn - INFO - ==================== 2026-01-16 10:54:11,789 - julearn - INFO - 2026-01-16 10:54:11,790 - julearn - INFO - = Model Parameters = 2026-01-16 10:54:11,791 - julearn - INFO - ==================== 2026-01-16 10:54:11,791 - julearn - INFO - 2026-01-16 10:54:11,792 - julearn - INFO - = Model Parameters = 2026-01-16 10:54:11,792 - julearn - INFO - ==================== 2026-01-16 10:54:11,792 - julearn - INFO - 2026-01-16 10:54:11,825 - julearn - INFO - = Model Parameters = 2026-01-16 10:54:11,826 - julearn - INFO - ==================== 2026-01-16 10:54:11,826 - julearn - INFO - 2026-01-16 10:54:11,826 - julearn - INFO - = Data Information = 2026-01-16 10:54:11,826 - julearn - INFO - Problem type: classification 2026-01-16 10:54:11,826 - julearn - INFO - Number of samples: 100 2026-01-16 10:54:11,826 - julearn - INFO - Number of features: 4 2026-01-16 10:54:11,826 - julearn - INFO - ==================== 2026-01-16 10:54:11,826 - julearn - INFO - 2026-01-16 10:54:11,826 - julearn - INFO - Number of classes: 2 2026-01-16 10:54:11,827 - julearn - INFO - Target type: object 2026-01-16 10:54:11,827 - julearn - INFO - Class distributions: species versicolor 50 virginica 50 Name: count, dtype: int64 2026-01-16 10:54:11,828 - julearn - INFO - Using outer CV scheme KFold(n_splits=5, random_state=None, shuffle=False) 2026-01-16 10:54:11,828 - julearn - INFO - Binary classification problem detected. 0 1.00 1 0.85 2 0.95 3 0.95 4 0.95 Name: test_score, dtype: float64 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.405 seconds) .. _sphx_glr_download_auto_examples_03_complex_models_run_stacked_models.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: run_stacked_models.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: run_stacked_models.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: run_stacked_models.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_