Skip to content

Support for empty levels

Compare
Choose a tag to compare
@mirand863 mirand863 released this 01 Jul 14:01
· 48 commits to main since this release
5f62ca1

With this release it becomes possible to train local hierarchical classifiers when the hierarchy has empty levels. For example:

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 = [
    ["Bird"],
    ["Reptile", "Snake"],
    ["Reptile", "Lizard"],
    ["Mammal", "Cat"],
    ["Mammal", "Wolf", "Dog"],
]

# 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)