注意
点击 here 下载完整的示例代码
你好 HiClass
一个极简示例,展示如何使用HiClass进行训练和预测。
输出:
[['Animal' 'Reptile' 'Lizard']
['Animal' 'Reptile' 'Snake']
['Animal' 'Mammal' 'Cow']
['Animal' 'Mammal' 'Sheep']]
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
rf = RandomForestClassifier()
classifier = LocalClassifierPerNode(local_classifier=rf)
# Train local classifier per node
classifier.fit(X_train, Y_train)
# Predict
predictions = classifier.predict(X_test)
print(predictions)
脚本总运行时间: ( 0 分钟 0.832 秒)