1

我已经使用 Rxgb.trainxgboost包中训练了一个模型。我试图了解该模型的特征的重要性。我不断收到以下错误:

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 
4

2 回答 2

4

这通常对我有用:

importance <- xgb.importance(dimnames(train)[[2]], model = myXGBfit)
于 2016-03-31T21:13:44.840 回答
0

将 R 版本从 3.2.0 更新到 3.2.4 修订后,该问题得到解决。运行该version命令会产生以下信息:

platform       x86_64-w64-mingw32                         
arch           x86_64                                     
os             mingw32                                    
system         x86_64, mingw32                            
status         Revised                                    
major          3                                          
minor          2.4                                        
year           2016                                       
month          03                                         
day            16                                         
svn rev        70336                                      
language       R                                          
version.string R version 3.2.4 Revised (2016-03-16 r70336)
nickname       Very Secure Dishes

为了更新 R 版本,我使用了installr包并updateR()从 R GUI 运行命令(仅适用于 Windows)。希望它可以帮助我遇到同样情况的任何人!

于 2016-04-05T13:10:29.800 回答