Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 无法使用XGBoost中的加权多类数据集生成预测 问题描述_Python 3.x_Machine Learning_Xgboost_Multiclass Classification - Fatal编程技术网

Python 3.x 无法使用XGBoost中的加权多类数据集生成预测 问题描述

Python 3.x 无法使用XGBoost中的加权多类数据集生成预测 问题描述,python-3.x,machine-learning,xgboost,multiclass-classification,Python 3.x,Machine Learning,Xgboost,Multiclass Classification,我有一个包含4个类的不平衡数据集,我正试图用XGBoost对其进行分类。目前,训练似乎进行得很顺利,我正在使用dMatrix=xgb.dMatrix(X,y,weight=weights)根据类突出度定义的权重来训练模型,我认为这可以确保我的分类不会被不平衡的数据集扭曲。唯一的问题是,我很难根据经过训练的模型生成预测。似乎我的输入仍然需要权重,我真的不明白为什么 当前实施 举重 类权重: 1 0.065769 0 0.080583 3 1.000000 2 1.0000

我有一个包含4个类的不平衡数据集,我正试图用XGBoost对其进行分类。目前,训练似乎进行得很顺利,我正在使用
dMatrix=xgb.dMatrix(X,y,weight=weights)
根据类突出度定义的权重来训练模型,我认为这可以确保我的分类不会被不平衡的数据集扭曲。唯一的问题是,我很难根据经过训练的模型生成预测。似乎我的输入仍然需要权重,我真的不明白为什么

当前实施
举重 类权重:

1    0.065769
0    0.080583
3    1.000000
2    1.000000
dtype: float64
创建元素权重向量 重量:

0       0.080583
1       0.080583
2       0.080583
3       0.080583
4       0.080583
          ...   
2453    0.065769
2454    0.065769
2455    0.065769
2456    0.065769
2457    0.065769
Length: 2458, dtype: float64
基于X、y和重量的训练 问题
这一切都很好,但我似乎不知道如何预测。例如,我试过

print(bst.predict(xgb.DMatrix(X.iloc[0])))
并得到以下错误:

ValueError: ('Expecting 2 dimensional numpy.ndarray, got: ', (486,))
与直觉相反,当我从

print(bst.predict(dMatrix))
我似乎得到了一些结果

[[0.6696256  0.10667633 0.18783426 0.0358638 ]
 [0.6733066  0.11801444 0.15131903 0.05735996]
 [0.66467386 0.14872473 0.14806929 0.03853212]
 ...
 [0.36380327 0.4005142  0.06459591 0.17108661]
 [0.12315215 0.60588646 0.0351514  0.23581001]
 [0.19565345 0.7347611  0.03038597 0.03919945]]
虽然

a) 我不确定为什么包括训练重量在预测中是相关的

b) 这个数据矩阵包括
y
,这对我来说似乎很奇怪,因为整个要点是预测
y

c) 我甚至不完全确定如何解释输出

问题:
如何使用权重在有偏差的数据集上进行训练,如何使用该模型进行预测

更新
如果我不使用举重,我可以很容易地把它举起来跑步:

model = XGBClassifier() 
model.fit(X, y)
for val in model.predict(X):
    print(val)
ValueError: ('Expecting 2 dimensional numpy.ndarray, got: ', (486,))
print(bst.predict(dMatrix))
[[0.6696256  0.10667633 0.18783426 0.0358638 ]
 [0.6733066  0.11801444 0.15131903 0.05735996]
 [0.66467386 0.14872473 0.14806929 0.03853212]
 ...
 [0.36380327 0.4005142  0.06459591 0.17108661]
 [0.12315215 0.60588646 0.0351514  0.23581001]
 [0.19565345 0.7347611  0.03038597 0.03919945]]
model = XGBClassifier() 
model.fit(X, y)
for val in model.predict(X):
    print(val)