Xgboost会产生相同的预测,而不管解释变量(R)如何

Xgboost会产生相同的预测,而不管解释变量(R)如何,r,xgboost,R,Xgboost,我有以下训练和测试数据,我正在使用带有预测器的数据集对其执行一个极端梯度增强算法(Xgboost),我知道该预测器具有预测能力,尽管模型的预测是恒定的,而与预测器的值无关: library(data.table) require(xgboost) library(Matrix) sparse_matrix_train = sparse.model.matrix(clicked~.-1, data = train) sparse_matrix_train2 = sparse.model.matr

我有以下训练和测试数据,我正在使用带有预测器的数据集对其执行一个
极端梯度增强算法
(Xgboost)
,我知道该预测器具有预测能力,尽管模型的预测是恒定的,而与预测器的值无关:

library(data.table)
require(xgboost)
library(Matrix)

sparse_matrix_train = sparse.model.matrix(clicked~.-1, data = train)
sparse_matrix_train2 = sparse.model.matrix(clicked~., data = test)
bst <- xgboost(data = sparse_matrix2, label = test2$clicked, max.depth = 2,
               eta = 0.3, nthread = 20, nround = 5,objective = "binary:logistic")
sparse_matrix_test = sparse.model.matrix(~., data = test)
test$pred_res<- predict(bst, sparse_matrix_test)
有人能详细说明一下吗

数据

train <- structure(list(clicked = c(0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 
  1L), prediction = c(0.116741800132, 0.148609212057, 0.27496222789, 
  0.0284488735744, 0.234446058524, 0.405107420156, 0.122376142849, 
  0.126600568099, 0.0636921765101, 0.385909171908), pred_res = c(0.293756693601608, 
  0.293756693601608, 0.293756693601608, 0.343792468309402, 0.293756693601608, 
  0.293756693601608, 0.293756693601608, 0.293756693601608, 0.293756693601608, 
  0.293756693601608)), .Names = c("clicked", "prediction", "pred_res"),
  row.names = c(NA, -10L), class = c("data.table", "data.frame"),
  .internal.selfref = <pointer: 0x1547c18>)

test <- structure(list(prediction = c(0.0553382017171, 0.158500277487, 
  0.155315011347, 0.118212821075, 0.0795492263212, 0.0272566752275, 
  0.159516005352, 0.218685440776, 0.0562459472969, 0.178293801444),
  pred_res = c(0.293756693601608, 0.293756693601608, 0.293756693601608, 
  0.293756693601608, 0.293756693601608, 0.293756693601608, 0.293756693601608, 
  0.293756693601608, 0.293756693601608, 0.293756693601608)),
  .Names = c("prediction","pred_res"), row.names = c(NA, -10L),
  class = c("data.table","data.frame"), .internal.selfref = <pointer: 0x1547c18>)

train我加载了您的数据并运行了您的代码,但得到:

xgb.get.DMatrix(数据、标签)中出错:找不到对象“稀疏矩阵”


嗯,皮特表哥

对不起,我看不到你的编辑。我可以建议你用一种容易重复错误的方式写问题吗?你的“训练”和“测试”集等可以挖出来,但为什么不让其他人更容易帮助你呢?因此,第一个库(xgboost)然后“train”设置为data.frame或矩阵格式,然后“test”设置与您使用的代码类似。理想情况下,我们应该能够将您的问题复制/粘贴到R中,并查看输出。把你的问题和数据放在这里,你就会明白我的意思。
train <- structure(list(clicked = c(0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 
  1L), prediction = c(0.116741800132, 0.148609212057, 0.27496222789, 
  0.0284488735744, 0.234446058524, 0.405107420156, 0.122376142849, 
  0.126600568099, 0.0636921765101, 0.385909171908), pred_res = c(0.293756693601608, 
  0.293756693601608, 0.293756693601608, 0.343792468309402, 0.293756693601608, 
  0.293756693601608, 0.293756693601608, 0.293756693601608, 0.293756693601608, 
  0.293756693601608)), .Names = c("clicked", "prediction", "pred_res"),
  row.names = c(NA, -10L), class = c("data.table", "data.frame"),
  .internal.selfref = <pointer: 0x1547c18>)

test <- structure(list(prediction = c(0.0553382017171, 0.158500277487, 
  0.155315011347, 0.118212821075, 0.0795492263212, 0.0272566752275, 
  0.159516005352, 0.218685440776, 0.0562459472969, 0.178293801444),
  pred_res = c(0.293756693601608, 0.293756693601608, 0.293756693601608, 
  0.293756693601608, 0.293756693601608, 0.293756693601608, 0.293756693601608, 
  0.293756693601608, 0.293756693601608, 0.293756693601608)),
  .Names = c("prediction","pred_res"), row.names = c(NA, -10L),
  class = c("data.table","data.frame"), .internal.selfref = <pointer: 0x1547c18>)