0
$\begingroup$

My question is specifically directed to the hiClass Python package for hierarchical classification (I am not sure if it is right to ask here, since I am not reporting an issue). After reading answer to this question that the package is actively supported.

I am working on a dataset for travel mode recognition problem. I would like to model the problem using hierarchical classification approach to proceed like in figure below:

enter image description here

The orange oval represent nodes and the green rectangle, the classes to predict.

I read in the related paper, that the class labels should be somehow transform into (n_samples x n_levels).

While features are exactly the same shape as expected for training flat models in scikit-learn, hierarchical training labels are represented as an array of shape n samples × n levels, where each column must contain either a label for the respective level in the hierarchy or an empty string that indicates missing labels in the leaf nodes.

Currently, my labels data structure in an array of shape (n_samples,):

>>> ytrain.shape
(31683,)

>>> ytrain[:10] # 0:walk, 1:bike, 2:bus, 3:car, 4:train
array([0, 0, 4, 1, 4, 2, 2, 3, 3, 3])

Questions

Assuming I am using the Local Classifier Per Parent Node algorithm:

  1. Is there a handy way to retrieve just the predicted classes (e.g. predicting just the "Bike" class instead of the hierarchical passway ["Root", "non-Motorised", "Bike"]?
  2. Having that my classes have different tree levels (Walk & Bike -> level-2, others level-3), How then should the hierarchy of the Walk & Bike classes be (["Root", "non-Motorised", "Bike"] or ["Root", "non-Motorised", "Bike", " "]) considering the statement I qouted above?

Cc: Fabio

$\endgroup$

1 Answer 1

2
$\begingroup$

I am the main developer of HiClass.

Apparently, from the URL you linked you are using a third-party package from globality-corp, which is developed by someone else. This is the correct link for HiClass, which is currently hosted on scikit-learn-contrib.

Answering your questions:

1. Is there a handy way to retrieve just the predicted classes (e.g. predicting just the "Bike" class instead of the hierarchical passway ["Root", "non-Motorised", "Bike"]? Unfortunately there is not an implementation to only return the leaf nodes at the moment, since the assumption we had with hierarchical classification is that all levels are important for the prediction. Please, correct me if I am wrong, but if you are only interested in the leaf nodes wouldn't flat classification be more appropriate for your use-case? I would need to update the algorithm to accommodate for that and it will probably take some time. I imagine an easier alternative would be for you to do some post-processing to return the last level that is not empty.

2. Having that my classes have different tree levels (Walk & Bike -> level-2, others level-3), How then should the hierarchy of the Walk & Bike classes be (["Root", "non-Motorised", "Bike"] or ["Root", "non-Motorised", "Bike", " "]) considering the statement I qouted above? It is fine to provide the labels with nested lists, i.e., just as ["Root", "non-Motorised", "Bike"] and HiClass will add empty levels as necessary.

Edit: I think it would be useful to link this example from the gallery of examples to complement my answer to question 2: training with different number of levels

For future questions, please feel free to open an issue on GitHub or send me an email since I only read stack exchange occasionally.

Best regards, Fabio

$\endgroup$
1
  • 1
    $\begingroup$ Thank you this detailed answer. $\endgroup$
    – arilwan
    Mar 16, 2023 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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