首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无论不同的解释变量(R)如何,Xgboost都会得到相同的预测结果

无论不同的解释变量(R)如何,Xgboost都会得到相同的预测结果
EN

Stack Overflow用户
提问于 2016-12-05 16:45:50
回答 1查看 337关注 0票数 1

我有以下训练和测试数据,我正在extreme gradient boosting algorithm (Xgboost)上对其执行,使用具有预测能力的数据集,尽管无论预测器值如何,模型的预测都是恒定的:

代码语言:javascript
复制
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)

请注意,test$pred_res具有相同的值:

代码语言:javascript
复制
test$pred_res
 [1] 0.2937567 0.2937567 0.2937567 0.2937567 0.2937567 0.2937567 0.2937567 0.2937567 0.2937567
[10] 0.2937567

有人能详细解释一下这个问题吗?

数据

代码语言:javascript
复制
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>)
EN

回答 1

Stack Overflow用户

发布于 2016-12-11 06:35:34

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

“xgb.get.DMatrix(数据,标签)中出错:找不到对象'sparse_matrix2‘”

HTH,cousin_pete

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40970241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档