在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)
答案 0 :(得分:0)
我已经能够解决该问题,在将分类值转换为数值时,我需要添加as.numeric