我有以下训练和测试数据,我正在extreme gradient boosting algorithm (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)请注意,test$pred_res具有相同的值:
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有人能详细解释一下这个问题吗?
数据
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>)发布于 2016-12-11 06:35:34
我加载了你的数据并运行了你的代码,但得到了:
“xgb.get.DMatrix(数据,标签)中出错:找不到对象'sparse_matrix2‘”
HTH,cousin_pete
https://stackoverflow.com/questions/40970241
复制相似问题