Multiclass multilabel classification in CatBoost - Stack Overflow

PHOTO EMBED

Sun Jul 12 2020 08:24:10 GMT+0000 (Coordinated Universal Time)

Saved by @david.starobinski

from catboost import CatBoostClassifier
from sklearn.multiclass import OneVsRestClassifier
from sklearn.preprocessing import MultiLabelBinarizer

##Using your example data 

X = [[1, 2, 3, 4], [2, 3, 5, 1], [4, 5, 1, 3]]

y = [[3, 1], [2, 8], [7, 8]]

mlb = MultiLabelBinarizer()
mlb.fit(y)
y_k_hot = mlb.transform(y)

ovr = OneVsRestClassifier(estimator=CatBoostClassifier(iterations=10,random_state=1))
ovr.fit(X,y_k_hot)

ovr.predict(X)*mlb.classes_

array([[1, 0, 3, 0, 0],
       [0, 2, 0, 0, 8],
       [0, 0, 0, 7, 8]])

content_copyCOPY

https://stackoverflow.com/questions/60166157/multiclass-multilabel-classification-in-catboost