使用sklearn和logisticRegress的多项式logit中的结果变量指定参考类别
我正在尝试使用Sklearn的LogisticRecression模块拟合多项式logit模型。
我的结果(y)有4个级别。我需要将这些级别之一指定为参考类别(或基线)。 LogisticRegress模块是否提供了指定此参考类别的方法?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Sklearn中多个类的LogisticRecression使用一个VS ALL或ALL或SOFTMAX参数化,具体取决于您是否指定了多项式。无论哪种情况,它都不使用参考来计算解决方案,而是计算每个输出类的系数向量。如果您使用多项式规范,则可以选择与您要设置的参考类别相对应的系数,并从其他方面减去该类别,该系数应将等效的解决方案恢复到您似乎想要的一个。
有关如何指定多项式:
LogisticRegression for multiple classes in sklearn uses either one vs all or a softmax parameterization of the problem, depending on whether you specify multinomial. In either case it does not compute the solution using a reference, but instead computes a vector of coefficients for each output class. If you use the multinomial specification you can select the coefficients corresponding to the reference category you would like to set and subtract that from the others, which should recover an equivalent solution to the one you seem to want.
See the docs for how to specify multinomial: https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html