python-3.x 标签二值化不支持多输出目标数据:OneVsRest分类器

5f0d552i  于 2023-05-08  发布在  Python
关注(0)|答案(1)|浏览(95)

我在尝试进行多类分类。下面是我的部分代码:

nb_classif = OneVsRestClassifier(MultinomialNB()).fit(X_train_dtm, y_train)
    C = 1.0 #SVregularization parameter
    svc = OneVsRestClassifier(svm.SVC(kernel='linear', C=C)).fit(X_train_dtm,                         y_train)
    lin_svc = OneVsRestClassifier(svm.LinearSVC(C=C)).fit(X_train_dtm, y_train)
    sgd = OneVsRestClassifier(SGDClassifier()).fit(X_train_dtm,y_train)

我得到了错误
标签二值化不支持多输出目标数据:OneVsRest分类器
我打印了我的X_train_dtm,输出是

(0, 184)      1
(0, 2674)     1
(0, 2399)     1
(0, 536)      1
(0, 2673)     1
(0, 1977)     1
(0, 2252)     1
(0, 2577)     1
(0, 1538)     1
(0, 1027)     1
(0, 2582)     1
(0, 750)      1
(0, 2663)     1
(0, 2544)     1
(0, 2159)     1
(0, 2150)     1
(0, 1309)     1
(0, 1737)     1
(0, 543)      1
(0, 340)      1
(0, 2229)     1
(0, 1321)     1
(0, 38)       1
(0, 2475)     1
(0, 1738)     1
:     :
(349, 1097)   1
(349, 2949)   2
(349, 1191)   1
(349, 1202)   1
(349, 1628)   1
(349, 2873)   2
(349, 264)    1
(349, 692)    1
(349, 1491)   1
(349, 2107)   1
(349, 1185)   1
(349, 1072)   1
(349, 433)    3
(349, 151)    1
(349, 2870)   2
(349, 194)    1
(349, 247)    1
(349, 2740)   1
(349, 2324)   1
(349, 379)    2
(349, 1027)   3
(349, 2582)   1
(349, 2475)   2
(349, 1939)   2
(349, 1136)   2
mv1qrgav

mv1qrgav1#

问题出在y_train上。检查是否有shape=(?, 1)shape=(?)

相关问题