.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_empty_levels.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_plot_empty_levels.py: ========================== Different Number of Levels ========================== HiClass supports different number of levels in the hierarchy. For this example, we will train a local classifier per node with a hierarchy similar to the following image: .. figure:: ../algorithms/local_classifier_per_node.svg :align: center .. GENERATED FROM PYTHON SOURCE LINES 14-43 .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/hiclass/envs/v5.0.0/lib/python3.12/site-packages/sklearn/base.py:474: FutureWarning: `BaseEstimator._validate_data` is deprecated in 1.6 and will be removed in 1.7. Use `sklearn.utils.validation.validate_data` instead. This function becomes public and is part of the scikit-learn developer API. warnings.warn( [['Mammal' 'Wolf' 'Dog'] ['Mammal' 'Cat' ''] ['Reptile' 'Lizard' ''] ['Reptile' 'Snake' ''] ['Bird' '' '']] | .. code-block:: Python import numpy as np from sklearn.linear_model import LogisticRegression from hiclass import LocalClassifierPerNode # Define data X_train = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] X_test = [[9, 10], [7, 8], [5, 6], [3, 4], [1, 2]] Y_train = np.array( [ ["Bird"], ["Reptile", "Snake"], ["Reptile", "Lizard"], ["Mammal", "Cat"], ["Mammal", "Wolf", "Dog"], ], dtype=object, ) # Use random forest classifiers for every node rf = LogisticRegression() classifier = LocalClassifierPerNode(local_classifier=rf) # Train local classifier per node classifier.fit(X_train, Y_train) # Predict predictions = classifier.predict(X_test) print(predictions) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.023 seconds) .. _sphx_glr_download_auto_examples_plot_empty_levels.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_empty_levels.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_empty_levels.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_empty_levels.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_