2
$\begingroup$

I'm a bit confused with the usage of logistic regression for multi-class classification. My understanding is that a logistic regression is dichotomous (two possible classes), so in the example of the Iris sepal/petal there are 3 Species:

1. *setosa*, 
2. *versicolor* and 
3. *virginca*

If we run a logistic regression on the Iris dataset, how can it distinguish between the 3 species?

code example:

model = LogisticRegression()
model.fit(x_train, y_train) 

predictions = model.predict(x_test)

results in:

array(['versicolor', 'setosa', 'virginica', 'versicolor', 'versicolor',
       'setosa', 'versicolor', 'virginica', 'versicolor', 'versicolor',
       'virginica', 'setosa', 'setosa', 'setosa', 'setosa', 'versicolor',
       'virginica', 'versicolor', 'versicolor', 'virginica', 'setosa',
       'virginica', 'setosa', 'virginica', 'virginica', 'virginica',
       'virginica', 'virginica', 'setosa', 'setosa'], dtype=object)
$\endgroup$
2
  • 1
    $\begingroup$ See the documentation: “ In the multiclass case, the training algorithm uses the one-vs-rest (OvR) scheme if the ‘multi_class’ option is set to ‘ovr’, and uses the cross-entropy loss if the ‘multi_class’ option is set to ‘multinomial’.” $\endgroup$ Commented Apr 28, 2022 at 14:30
  • 3
    $\begingroup$ Multinomial logistic regression generalizes logistic regression to more than 2 outcomes. en.wikipedia.org/wiki/Multinomial_logistic_regression $\endgroup$
    – Sycorax
    Commented Apr 28, 2022 at 14:30

1 Answer 1

7
$\begingroup$

Extending my comment into an answer:

There are several natural extensions to handle multiple classes, and two are built into scikit-learn. Multinomial logistic regression is still logistic regression. And one-versus-rest classification is another common way to extend a binary classifier to multiple classes.

See the scikit-learn LogisticRegression documentation for how multi-class prediction is handled in the software you’re using.

In the multiclass case, the training algorithm uses the one-vs-rest (OvR) scheme if the ‘multi_class’ option is set to ‘ovr’, and uses the cross-entropy loss if the ‘multi_class’ option is set to ‘multinomial’.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.