scikit multilabel classification: ValueError: bad input shape

丶灬走出姿态 提交于 2019-12-23 01:21:10

问题


I beieve SGDClassifier() with loss='log' supports Multilabel classification and I do not have to use OneVsRestClassifier. Check this

Now, my dataset is quite big and I am using HashingVectorizer and passing result as input to SGDClassifier. My target has 42048 features.

When I run this, as follows:

clf.partial_fit(X_train_batch, y)

I get: ValueError: bad input shape (300000, 42048).

I have also used classes as the parameter as follows, but still same problem.

clf.partial_fit(X_train_batch, y, classes=np.arange(42048))

In the documentation of SGDClassifier, it says y : numpy array of shape [n_samples]


回答1:


No, SGDClassifier does not do multilabel classification -- it does multiclass classification, which is a different problem, although both are solved using a one-vs-all problem reduction.

Then, neither SGD nor OneVsRestClassifier.fit will accept a sparse matrix for y. The former wants an array of labels, as you've already found out. The latter wants, for multilabel purposes, a list of lists of labels, e.g.

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

to denote that X[0] has label 1, X[1] has labels {2,3} and X[2] has labels {1,3}.



来源:https://stackoverflow.com/questions/20335853/scikit-multilabel-classification-valueerror-bad-input-shape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!