【发布时间】:2020-09-27 12:10:35
【问题描述】:
我有multiclass multioutput分类(详见https://scikit-learn.org/stable/modules/multiclass.html)。换句话说,我的数据集如下所示。
node_name, feature1, feature2, ... label_1, label_2
node1, 1.2, 1.8, ..., 0, 2
node2, 1.0, 1.1, ..., 1, 1
node3, 1.9, 1.2, ..., 0, 3
...
...
...
所以,我的 label_1 可能是 0 or 1,而我的 label_2 可能是 0, 1, or 2。
由于我有两个标签(即 label_1 和 label_2),我的问题是如何将这些标签适合 sklearn 中的分类器?
在我当前的代码中,我使用的是RandomForest,如下所述。但是,我找不到有用的资源来描述如何将随机森林分类器转换为多类多标签分类。如果 RandomForest 不支持多类多标签分类,我完全可以进入支持它们的其他分类器。我目前的代码如下。
clf = RandomForestClassifier(random_state = 42, class_weight="balanced")
k_fold = StratifiedKFold(n_splits=10, shuffle=True, random_state=0)
scores = cross_validate(clf, X, y, cv=k_fold, scoring = ('accuracy', 'precision_weighted', 'recall_weighted', 'f1_weighted', 'roc_auc'))
如果需要,我很乐意提供更多详细信息。
【问题讨论】:
标签: python scikit-learn classification