我们知道,在逻辑回归模型的二元分类中,默认的成功阈值是> 0.5。
我想知道如果预测的成功和失败的概率恰好是0.5,这个模型的输出会是什么?有人能帮我解释一下吗?
回答:
从理论上讲,你可以决定如何处理那些概率p = 0.5
的样本。
如果你问的是sklearn逻辑回归实现的决策边界 –
这是源代码中的预测方法:
def predict(self, X): """ Predict class labels for samples in X. Parameters ---------- X : array_like or sparse matrix, shape (n_samples, n_features) Samples. Returns ------- C : array, shape [n_samples] Predicted class label per sample. """ scores = self.decision_function(X) if len(scores.shape) == 1: indices = (scores > 0).astype(np.int) else: indices = scores.argmax(axis=1) return self.classes_[indices]
你可以看到他们使用了argmax:indices = scores.argmax(axis=1)
—— 这意味着如果有两个类别的概率都是0.5,它会选择第一个类别(类别0);这就是argmax的工作方式。
scores = np.array([[0.5, 0.5]])scores.argmax(axis=1)Out[5]: array([0])