4

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]

Community
  • 1
  • 1
user644745
  • 5,673
  • 9
  • 54
  • 80

1 Answers1

5

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}.

Leb
  • 15,483
  • 10
  • 56
  • 75
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • Thanks Larsmans. I further worked on it and got all my answers clarified. But I am worried now as there are about 42000+ labels, I might have to come up with 42K estimators for each of the labels separately and I do not think I can do all these in a single machine. Thinking of using ipython parallel and starcluster. – user644745 Dec 04 '13 at 04:00
  • ValueError: You appear to be using a legacy multi-label data representation. Sequence of sequences are no longer supported; use a binary array or sparse matrix instead - the MultiLabelBinarizer transformer can convert to this format. – keramat Oct 28 '21 at 10:10