为什么predict_proba函数以相反的顺序打印概率?

问题描述 投票:3回答:2

我正在使用scikit-learn使用Logistic回归实现分类。使用predict()函数预测类标签,而使用predict_proba()函数打印预测概率。

代码段粘贴在下面:

# Partition the dataset into train and test data
X_train, X_test, y_train, y_test = train_test_split(ds_X, ds_y, test_size=0.33, random_state=42) 

y_pred = logreg.predict(X_test)                             # Predicted class labels from test features
y_predicted_proba = logreg.predict_proba(X_test)            # Predicted probabilities from test features

预测标签打印为

array([1, 1, 1, 1, 1, 1, 1, 1, 0, 1.......... and so on

相应的预测概率打印为

array([[ 0.03667012,  0.96332988],
       [ 0.03638475,  0.96361525],
       [ 0.03809274,  0.96190726],
       [ 0.01746768,  0.98253232],
       [ 0.02742639,  0.97257361],
       [ 0.03676579,  0.96323421],
       [ 0.02881874,  0.97118126],
       [ 0.03082288,  0.96917712],
       [ 0.65332179,  0.34667821],
       [ 0.02091977,  0.97908023],
                   .
                   '
       and so on

观察, 第一个预测的标签 - 1 第一个预测概率 - [0.03667012,0.96332988] 为什么0.03667012首先打印而不是0.96332988?它应该是另一种方式吗?

python machine-learning scikit-learn logistic-regression
2个回答
5
投票

第0列是第0类的概率,第1列是第1类的概率。如果你有n个类,则输出概率形状将是(n_examples,n_classes)。


0
投票

您可以使用:logreg.classes_来解析概率数组中的哪个元素对应于哪个类。在你的情况下它的[False,True]

© www.soinside.com 2019 - 2024. All rights reserved.