.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_multilabel.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_multilabel.py: ============================================== Using Hierarchical Multi-Label Classification ============================================== A simple example to show how to use multi-label classification in HiClass. Please have a look at Algorithms Overview Section for :ref:`Multi-Label Classification` for the motivation and background behind the implementation. .. GENERATED FROM PYTHON SOURCE LINES 10-38 .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [[['Mammal' 'Human'] ['Fish' '']] [['Mammal' 'Human'] ['Mammal' 'Bovine']] [['Mammal' 'Human'] ['' '']]] | .. code-block:: default import numpy as np from sklearn.tree import DecisionTreeClassifier from hiclass.MultiLabelLocalClassifierPerNode import MultiLabelLocalClassifierPerNode # Define data X_train = [[1, 2], [3, 4], [5, 6]] X_test = [[1, 2], [3, 4], [5, 6]] # Define labels Y_train = np.array( [ [["Mammal", "Human"], ["Fish"]], # Mermaid [["Mammal", "Human"], ["Mammal", "Bovine"]], # Minotaur [["Mammal", "Human"]], # just a Human ], dtype=object, ) # Use decision tree classifiers for every node tree = DecisionTreeClassifier() classifier = MultiLabelLocalClassifierPerNode(local_classifier=tree) # 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.006 seconds) .. _sphx_glr_download_auto_examples_plot_multilabel.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_multilabel.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_multilabel.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_