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

标签 python machine-learning scikit-learn logistic-regression

我正在使用 scikit-learn 通过逻辑回归来实现分类。 使用 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 ? 应该是另一种方式吗?

最佳答案

第 0 列是第 0 类的概率,

第 1 列是类别 1 的概率。

如果您有 n 个类别,则输出概率形状将为 (n_examples, n_classes)。

关于python - 为什么 predict_proba 函数以相反的顺序打印概率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42241991/

相关文章:

python - YouCompleteMe 不适用于 python

statistics - K 最近邻分类的“概率”

python - 如何查看从 Select 中选择了哪些变量

python - 在 Python 中比较列表和省略号

android - 在 Windows 中将 MonkeyRunner 导入 Python 脚本失败

windows - 有多少个可用于 Windows 的设备驱动程序

python - sklearn - 从文本文档预测多标签分类中的前 3-4 个标签

python - 如何使用 GridSearchCV 输出进行 scikit 预测?

python - 列出所有TSP路由组合(5个顶点)

machine-learning - 为什么我无法恢复这个模型?