As per the scikit multiclass classification Logistic regression can be used for multi-class classification by setting multi_class=multinomial in the the constructor. But doing this gives error:
Code:
text_clf = Pipeline([('vect', TfidfVectorizer()),('clf', LogisticRegression(multi_class = 'multinomial')),])
text_clf = text_clf.fit(X_train, Y_train)
Error:
ValueError: Solver liblinear does not support a multinomial backend.
Can you tell me what is wrong here?
Note: Keeping multi_class to blank i.e. "ovr" is working fine but it fits a binary model for each classifier and I want to try mutlinomial feature also.
One popular approach for adapting logistic regression to multi-class classification problems is to split the multi-class classification problem into multiple binary classification problems and fit a standard logistic regression model on each subproblem.
Yes, we can apply logistic regression on 3 classification problem, We can use One Vs all method for 3 class classification in logistic regression.
Logistic regression uses a sigmoid function to predict the output.
Scikit Learn - Logistic Regression. Advertisements. Previous Page. Next Page. Logistic regression, despite its name, is a classification algorithm rather than regression algorithm. Based on a given set of independent variables, it is used to estimate discrete value (0 or 1, yes/no, true/false). It is also called logit or MaxEnt Classifier.
Logistic regression is a very popular machine learning technique. We use logistic regression when the dependent variable is categorical. This article will focus on the implementation of logistic regression for multiclass classification problems. I am assuming that you already know how to implement a binary classification with Logistic Regression.
Logistic Regression (aka logit, MaxEnt) classifier. 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’.
There are several Multiclass Classification Models like Decision Tree Classifier, KNN Classifier, Naive Bayes Classifier, SVM (Support Vector Machine) and Logistic Regression. We will take one of such a multiclass classification dataset named Iris. We will use several models on it.
It looks like you are not providing solver & by default solver is set to 'liblinear' that does not support multi class. As per sklearn version 0.20.1, multiclass is being supported by ‘newton-cg’, ‘lbfgs’, ‘sag’, ‘saga’ not by ‘liblinear’ so change your instance creation for LogisticRegression as per following code
logReg = LogisticRegression(multi_class='multinomial', solver='newton-cg')
solver must be anything from ‘newton-cg’, ‘lbfgs’, ‘sag’, ‘saga’ but can not be left
From the doc:
Currently the ‘multinomial’ option is supported only by the ‘lbfgs’ and ‘newton-cg’ solvers.
So you need to explicitly set solver
to 'newton-cg
' or 'lbfgs'
, since the default solver is 'liblinear'
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With