gpt4 book ai didi

python - xgboost predict_proba : How to do the mapping between the probabilities and the labels

转载 作者:太空宇宙 更新时间:2023-11-03 15:34:56 26 4
gpt4 key购买 nike

我正在尝试使用 xgboost 算法预测解决多类分类问题,但我不知道 predict_proba 是如何工作的。事实上,predict_proba 生成了一个概率列表,但我不知道每个概率与哪个类相关。

这是一个简单的例子:

这是我的火车数据:

+------------+----------+-------+
| feature1 | feature2 | label |
+------------+----------+-------+
| x | z | 3 |
+------------+----------+-------+
| y | u | 0 |
+------------+----------+-------+
| x | u | 2 |
+------------+----------+-------+

然后当我尝试预测新示例的概率时

model.predict_proba(['x','u'])

这将返回如下内容:

[0.2, 0.3, 0.5]

我的问题是:概率为 0.5 的类别是什么?是 2 级、3 级还是 0 级?

最佳答案

看来你用的是xgboost的sklearn API。在这种情况下,模型有一个专用属性 model.classes_,它返回模型学习的类,输出数组中类的顺序对应于概率的顺序。

这是一个带有虚拟数据的例子:

import numpy as np
import pandas as pd
import xgboost as xgb

# generate dummy data (10k examples, 10 numeric features, 4 classes of target)
np.random.seed(312)
train_X = np.random.random((10000,10))
train_y_mcc = np.random.randint(0, 4, train_X.shape[0]) #four classes:0,1,2,3

# model
xgb_model_mpg = xgb.XGBClassifier(max_depth= 3, n_estimators=100)
xgb_model_mpg.fit(train_X, train_y_mcc)

# classes
print(xgb_model_mpg.classes_)
>>> [0 1 2 3]

关于python - xgboost predict_proba : How to do the mapping between the probabilities and the labels,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55420610/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com