1

在 R 中使用 XGBoost 时出现此错误

Error in xgb.DMatrix(data, label = label, missing = missing) : 
  'data' has class 'character' and length 1791.
  'data' accepts either a numeric matrix or a single filename.

下面是正在运行的代码

#importing the dataset
XGBoostDataSet_Hr_Admin <- read.csv("CompletedDataImputed_HR_Admin.csv")

#Use factor function to convert categorical data to numerical data
XGBoostDataSet_Hr_Admin$Salary = factor(XGBoostDataSet_Hr_Admin$Salary, levels =c('L','M', 'H', 'V'), labels =c(1,2,3,4))


#split the data in train dataset and test dataset


#fitting XGBoost to the Training Test
library(xgboost)
classifier = xgboost(data = as.matrix(training_set[-10]), label = training_set$Employee_Turnover, nrounds = 10)
4

1 回答 1

0

我已经能够解决这个问题,我需要在将分类值转换为数值时添加 as.numeric

于 2019-11-13T13:51:10.410 回答