更新时间:2021-12-29 10:01:23
我注意到这个问题现在已经很老了,但希望这可以帮助某人.使用 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.