How to use multinomial logistic regression for multilabel classification problem?

前端 未结 1 1970
陌清茗
陌清茗 2021-01-26 11:15

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 pro

相关标签:
1条回答
  • 2021-01-26 11:58

    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:])
    
    0 讨论(0)
提交回复
热议问题