Answer a question

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.

Answers

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

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐