Python中的加权逻辑回归 [英] Weighted logistic regression in Python

查看:99
本文介绍了Python中的加权逻辑回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找 Python 中逻辑回归(未正则化)的良好实现.我正在寻找一个包,它也可以为每个向量获取权重.谁能建议一个好的实现/包?谢谢!

I'm looking for a good implementation for logistic regression (not regularized) in Python. I'm looking for a package that can also get weights for each vector. Can anyone suggest a good implementation / package? Thanks!

推荐答案

我注意到这个问题现在已经很老了,但希望这可以帮助某人.使用 sklearn,您可以使用 SGDClassifier 类通过简单地传入log"作为损失来创建逻辑回归模型:

I notice that this question is quite old now but hopefully this can help someone. With sklearn, you can use the SGDClassifier class to create a logistic regression model by simply passing in 'log' as the loss:

sklearn.linear_model.SGDClassifier(loss='log', ...).

这个类在fit()函数中实现了加权样本:

This class implements weighted samples in the fit() function:

classifier.fit(X, Y, sample_weight=weights)

其中权重是一个包含样本权重的数组,其长度(显然)必须与 X 中的数据点数相同.

where weights is a an array containing the sample weights that must be (obviously) the same length as the number of data points in X.

参见 http://scikit-learn.org/dev/modules/generated/sklearn.linear_model.SGDClassifier.html 获取完整文档.

See http://scikit-learn.org/dev/modules/generated/sklearn.linear_model.SGDClassifier.html for full documentation.

这篇关于Python中的加权逻辑回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆