Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi output target data is not supported with label binarization : OneVsRest Classifier

I'm trying to perform a multiclass classification. Here is my portion of the code:

    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)

I'm getting the error

Multi output target data is not supported with label binarization: OneVsRest Classifier

I printed my X_train_dtm and the output is

(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
like image 448
venkatesh .b Avatar asked Oct 30 '25 09:10

venkatesh .b


1 Answers

The problem is in your y_train. Check that it either has a shape=(?, 1) or shape=(?).

like image 86
Jan K Avatar answered Oct 31 '25 23:10

Jan K