.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_binary_policies.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_binary_policies.py: =========================== Binary Training Policies =========================== The siblings policy is used by default on the local classifier per node, but the remaining ones can be selected with the parameter :literal:`binary_policy`, for example: .. tabs:: .. code-tab:: python :caption: Exclusive rf = RandomForestClassifier() classifier = LocalClassifierPerNode(local_classifier=rf, binary_policy="exclusive") .. code-tab:: python :caption: Less exclusive rf = RandomForestClassifier() classifier = LocalClassifierPerNode(local_classifier=rf, binary_policy="less_exclusive") .. code-tab:: python :caption: Less inclusive rf = RandomForestClassifier() classifier = LocalClassifierPerNode(local_classifier=rf, binary_policy="less_inclusive") .. code-tab:: python :caption: Inclusive rf = RandomForestClassifier() classifier = LocalClassifierPerNode(local_classifier=rf, binary_policy="inclusive") .. code-tab:: python :caption: Siblings rf = RandomForestClassifier() classifier = LocalClassifierPerNode(local_classifier=rf, binary_policy="siblings") .. code-tab:: python :caption: Exclusive siblings rf = RandomForestClassifier() classifier = LocalClassifierPerNode(local_classifier=rf, binary_policy="exclusive_siblings") In the code below, the inclusive policy is selected. However, the code can be easily updated by replacing lines 20-21 with the examples shown in the tabs above. .. seealso:: Mathematical definition on the different policies is given at :ref:`Training Policies`. .. GENERATED FROM PYTHON SOURCE LINES 54-79 .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [['Animal' 'Mammal' 'Sheep'] ['Animal' 'Mammal' 'Sheep'] ['Animal' 'Mammal' 'Sheep'] ['Animal' 'Mammal' 'Sheep']] | .. code-block:: default from sklearn.ensemble import RandomForestClassifier from hiclass import LocalClassifierPerNode # Define data X_train = [[1], [2], [3], [4]] X_test = [[4], [3], [2], [1]] Y_train = [ ["Animal", "Mammal", "Sheep"], ["Animal", "Mammal", "Cow"], ["Animal", "Reptile", "Snake"], ["Animal", "Reptile", "Lizard"], ] # Use random forest classifiers for every node # And inclusive policy to select training examples for binary classifiers. rf = RandomForestClassifier() classifier = LocalClassifierPerNode(local_classifier=rf, binary_policy="inclusive") # 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.010 seconds) .. _sphx_glr_download_auto_examples_plot_binary_policies.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_binary_policies.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_binary_policies.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_