码迷,mamicode.com
首页 > 其他好文 > 详细

multilabel-multiclass classifier

时间:2021-01-11 10:48:14      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:区别   mode   sel   ase   out   xgboost   classes   form   false   

multiclass与multilabel的区别

  • multiclass分类是指n取1
  • multilabel分类是指n取k

对于xgboost,如果想要做multiclass分类可以借助sklearn的 from sklearn.multiclass import OneVsRestClassifier 。想要做multilabel分类,可以借助sklearn的 from sklearn.multioutput import MultiOutputClassifier。举例如下:

import xgboost as xgb
from sklearn.datasets import make_multilabel_classification
from sklearn.model_selection import train_test_split
from sklearn.multioutput import MultiOutputClassifier
from sklearn.metrics import accuracy_score

# create sample dataset
X, y = make_multilabel_classification(n_samples=3000, n_features=45, n_classes=20, n_labels=1,
                                      allow_unlabeled=False, random_state=42)

# split dataset into training and test set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=123)

# create XGBoost instance with default hyper-parameters
xgb_estimator = xgb.XGBClassifier(objective=‘binary:logistic‘)

# create MultiOutputClassifier instance with XGBoost model inside
multilabel_model = MultiOutputClassifier(xgb_estimator)

# fit the model
multilabel_model.fit(X_train, y_train)

# evaluate on test data
print(‘Accuracy on test data: {:.1f}%‘.format(accuracy_score(y_test, multilabel_model.predict(X_test))*100))

multilabel-multiclass classifier

标签:区别   mode   sel   ase   out   xgboost   classes   form   false   

原文地址:https://www.cnblogs.com/zongfa/p/14249270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!