Skip to main content
 首页 » 编程设计

python之python sklearn分类器使用的概率分布是什么

2024年10月01日8artech

在使用我的 sklearn 分类器的预测函数时,我想看看它用于预测的概率分布,以估计置信度度量。

我正在使用以下简单的分类器配置:

clf = SGDClassifier(loss='log',penalty='l2',alpha=1e-3, n_iter=5, random_state=42).fit(X, Y) 

我使用的预测是:

    predicted = clf.predict(X_test)    
    proba = clf.predict_proba(X_test)[0] 

但是当查看概率分布“proba”时,我意识到具有最大概率值的类别并不总是与“预测”变量中的类别相同。这是为什么?如何获得与预测函数中使用的概率分布相同的概率分布?

请您参考如下方法:

来自SGDClassifier.predict_proba()文档:

Binary probability estimates for loss=”modified_huber” are given by (clip(decision_function(X), -1, 1) + 1) / 2. For other loss functions it is necessary to perform proper probability calibration by wrapping the classifier with sklearn.calibration.CalibratedClassifierCV instead.

在您的示例代码中,您正在使用 loss="log",但没有按照说明包装您的分类器,这可能就是您看到 predict() 之间存在差异的原因 和 predict_proba()。