How To Use Multinomial Logistic Regression For Multilabel Classification Problem?
I have to predict the type of program a student is in based on other attributes. prog is a categorical variable indicating what type of program a student is in: “General” (1),
Solution 1:
As such, LogisticRegression
does not handle multiple targets. But this is not the case with all the model in Sklearn. For example, all tree based models (DecisionTreeClassifier
) can handle multi-output natively.
To make this work for LogisticRegression
, you need a MultiOutputClassifier
wrapper.
Example:
import numpy as np
from sklearn.datasets import make_multilabel_classification
from sklearn.multioutput import MultiOutputClassifier
from sklearn.linear_model import LogisticRegression
X, y = make_multilabel_classification(n_classes=3, random_state=0)
clf = MultiOutputClassifier(estimator= LogisticRegression()).fit(X, y)
clf.predict(X[-2:])
Post a Comment for "How To Use Multinomial Logistic Regression For Multilabel Classification Problem?"