简体   繁体   English

带R的xgboost的问题

[英]Questions of xgboost with R

I used xgboost to do logistic regression. 我使用xgboost进行逻辑回归。 I followed the steps from , but I got two problems.The datasets are found here . 我遵循的步骤 ,但我有两个problems.The数据集被发现在这里

First, when I run the follow code: 首先,当我运行以下代码时:

bst <- xgboost(data = sparse_matrix, label = output_vector,nrounds = 39,param)

Then, I got 然后,我得到了

 [0]train-rmse:0.350006
 [1]train-rmse:0.245008
 [2]train-rmse:0.171518
 [3]train-rmse:0.120065
 [4]train-rmse:0.084049
 [5]train-rmse:0.058835
 [6]train-rmse:0.041185
 [7]train-rmse:0.028830
 [8]train-rmse:0.020182
 [9]train-rmse:0.014128
[10]train-rmse:0.009890
[11]train-rmse:0.006923
[12]train-rmse:0.004846
[13]train-rmse:0.003392
[14]train-rmse:0.002375
[15]train-rmse:0.001662
[16]train-rmse:0.001164
[17]train-rmse:0.000815
[18]train-rmse:0.000570
[19]train-rmse:0.000399
[20]train-rmse:0.000279
[21]train-rmse:0.000196
[22]train-rmse:0.000137
[23]train-rmse:0.000096
[24]train-rmse:0.000067
[25]train-rmse:0.000047
[26]train-rmse:0.000033
[27]train-rmse:0.000023
[28]train-rmse:0.000016
[29]train-rmse:0.000011
[30]train-rmse:0.000008
[31]train-rmse:0.000006
[32]train-rmse:0.000004
[33]train-rmse:0.000003
[34]train-rmse:0.000002
[35]train-rmse:0.000001
[36]train-rmse:0.000001
[37]train-rmse:0.000001
[38]train-rmse:0.000000

train-rmse is finally equal to 0! train-rmse最终等于0! Is that normal? 那是正常的吗? Usually,I know train-rmse can't be equal to 0. So,where is my problem? 通常,我知道train-rmse不能等于0。那么,我的问题在哪里?

Second, when I run 第二,我跑步的时候

importance <- xgb.importance(sparse_matrix@Dimnames[[2]], model = bst)

Then, I got a Error: 然后,我得到一个错误:

Error in eval(expr, envir, enclos) : object 'Yes' not found. eval(expr,envir,enclos)中的错误:找不到对象“是”。

I don't know what does it mean, maybe the first question leads to the second one. 我不知道这是什么意思,也许第一个问题导致了第二个问题。

library(data.table)
train_x<-fread("train_x.csv")
str(train_x)
train_y<-fread("train_y.csv")
str(train_y)
train<-merge(train_y,train_x,by="uid")
train$uid<-NULL
test<-fread("test_x.csv")
require(xgboost)
require(Matrix)
sparse_matrix <- sparse.model.matrix(y~.-1, data = train)
head(sparse_matrix)
output_vector = train[,y] == "Marked"
param <- list(objective = "binary:logistic", booster = "gblinear",
          nthread = 2, alpha = 0.0001,max.depth = 4,eta=1,lambda = 1)
bst <- xgboost(data = sparse_matrix, label = output_vector,nrounds = 39,param)
importance <- xgb.importance(sparse_matrix@Dimnames[[2]], model = bst)

I ran into the same problem (Error in eval(expr, envir, enclos) : object 'Yes' not found.) and the reason was the following: 我遇到了同样的问题(eval(expr,envir,enclos)错误:找不到对象“是”。)原因如下:

I tried to do 我试着做

dt = data.table(x = runif(10), y = 1:10, z = 1:10)
label = as.logical(dt$z)
train = dt[, z := NULL]
trainAsMatrix = as.matrix(train)
label = as.matrix(label)

bst <- xgboost(data = trainAsMatrix, label = label, max.depth = 8,
               eta = 0.3, nthread = 2, nround = 50, objective = "reg:linear")
bst$featureNames = names(train)
xgb.importance(model = bst)

The problem comes from the line 问题出在线路上

label = as.logical(dt$z)

I got this line in there because the last time I used xgboost, I wanted to predict a categorial variable. 之所以会出现这一行,是因为上次使用xgboost时,我想预测一个类别变量。 Now since I want to do regression it should read: 现在,由于我要进行回归分析,因此应显示为:

label = dt$z

Maybe something similar causes the problem in your case? 也许类似的情况导致了您的问题?

Perhaps this is of any help. 也许这有什么帮助。 I'm often getting the same error when the labels have zero variation. 当标签的变化为零时,我经常会遇到相同的错误。 Using the current CRAN version of xgboost, which is somewhat old already (0.4.4). 使用xgboost的当前CRAN版本,该版本已经有些旧了(0.4.4)。 xgb.train happily accepts this (showing a .50 AUC) but the error then shows when calling xgb.importance. xgb.train愉快地接受了这一点(显示.50 AUC),但是在调用xgb.importance时显示了错误。

Cheers 干杯

Otto 玫瑰油

[0] train-auc:0.500000  validate-auc:0.500000
[1] train-auc:0.500000  validate-auc:0.500000
[2] train-auc:0.500000  validate-auc:0.500000
[3] train-auc:0.500000  validate-auc:0.500000
[4] train-auc:0.500000  validate-auc:0.500000

[1] "XGB error: Error in eval(expr, envir, enclos): object 'Yes' not found\n"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM