The Python Oracle

Multi-Class Logistic Regression in SciKit Learn

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Quiet Intelligence

--

Chapters
00:00 Multi-Class Logistic Regression In Scikit Learn
01:29 Accepted Answer Score 18
02:56 Thank you

--

Full question
https://stackoverflow.com/questions/3652...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #machinelearning #scikitlearn #logisticregression

#avk47



ACCEPTED ANSWER

Score 19


You seem to be confusing terms multiclass and multilabel http://scikit-learn.org/stable/modules/multiclass.html , in short:

  • Multiclass classification means a classification task with more than two classes; e.g., classify a set of images of fruits which may be oranges, apples, or pears. Multiclass classification makes the assumption that each sample is assigned to one and only one label: a fruit can be either an apple or a pear but not both at the same time.

Thus data is [n_samples, n_features] and labels are [n_samples]

  • Multilabel classification assigns to each sample a set of target labels. This can be thought as predicting properties of a data-point that are not mutually exclusive, such as topics that are relevant for a document. A text might be about any of religion, politics, finance or education at the same time or none of these.

Thus data is [n_samples, n_features] and labels are [n_samples, n_labels]

And you seem to be looking for multilabel (as for multiclass labels should be 1-dim). Currently, in sklearn, the only methods supporting multilabel are: Decision Trees, Random Forests, Nearest Neighbors, Ridge Regression.

If you want to learn multlabel problem with diffent model, simply use OneVsRestClassifier as a multilabel wrapper around your LogisticRegression

http://scikit-learn.org/stable/modules/generated/sklearn.multiclass.OneVsRestClassifier.html#sklearn.multiclass.OneVsRestClassifier