我已经使用 Rxgb.train
从xgboost
包中训练了一个模型。我试图了解该模型的特征的重要性。我不断收到以下错误:
Error in fread(paste(longString, collapse = ""), sep = "\n", header = F) :
4 arguments passed to .Internal(nchar) which requires 3
我在这里分享我的代码以防有帮助:
# Make the xgb.DMatrix
train <- sparse.model.matrix(TARGET ~ ., data = train)
dtrain <- xgb.DMatrix(data=train, label=train.y)
# Set the desired parameters
myParams <- list(objective = "binary:logistic",
booster = "gbtree",
eval_metric = "auc",
eta = 0.02,
max_depth = 5,
min_child_weight = 12,
gamma = 0.1,
subsample = 0.7,
colsample_bytree = 0.7)
# Train model
myXGBfit <- xgb.train(params = myParams,
data = dtrain,
nrounds = 369,
verbose = 1,
watchlist = watchlist,
maximize = FALSE)
# Calculate feature importance matrix
importance <- xgb.importance(feature_names = train@Dimnames[[2]], model = myXGBfit)
我尝试使用xgboost
而不是xgb.train
训练模型,但是在尝试获取特征重要性矩阵时遇到了同样的错误。我还阅读了该xgboost
软件包的文档并在线搜索了帮助,但无法找到解决方案。我究竟做错了什么?
如果有任何用处,sessionInfo()
请提供以下信息:
R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] pROC_1.8 Matrix_1.2-4 xgboost_0.4-3
loaded via a namespace (and not attached):
[1] plyr_1.8.3 magrittr_1.5 tools_3.2.0 yaml_2.1.13 Rcpp_0.12.3
[6] stringi_1.0-1 grid_3.2.0 knitr_1.12.3 data.table_1.9.6 stringr_1.0.0
[11] chron_2.3-47 lattice_0.20-33