Currently, I'm using Scikit-learn in Python 3.6 to classify data with a 7-8 classes (e.g. [C, A.1, A.2, B.3, B.1.1, B.1.2, B.2.1, B.2.2] represented by dark borders below) but I started realizing that there is an inherent hierarchy in these groups that could be used during classification. I was going to write my own algorithm but I don't want to reinvent the wheel if one exists.

Does an algorithm that can predict class-labels in hierarchical manner like this exist (preferably in Python)? If not, are there any examples of an approach like this being used? It reminds me of layers in a neural network but I do not have nearly enough samples for a neural net.

For example, A.1 and A.2 in Level-1 are subgroups of Level-0_A. Level-0_C has no subgroups.

enter image description here


I couldn't find an implementation of Hierarchical Classification on scikit-learn official documentation. But I found this repository recently. This module is based on scikit-learn's interfaces and conventions. I hope this will be useful.


It's possible to install it with pip:

pip install sklearn-hierarchical-classification

A thorough usage example is provided in the repo .

  • $\begingroup$ Hi! If anyone was able to figure out how to use this package for deep hierarchy - please post a ling here if you could? For me it works for depth as in provided example, but I am not certain how to properly pass a deeper hierarchy $\endgroup$ – Maksim Khaitovich Aug 29 '18 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.