2

am getting this error when using XGBoost in R

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.

Below is the code am running

#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)
ibocus
  • 45
  • 1
  • 9
  • you still have characters insider training_set[-10], thats why everything is converted to character – StupidWolf Nov 12 '19 at 13:04
  • 1
    hello StupidWolf, I have been able to resolve the issue, i needed to added the as.numeric when converting categorical values to numerical values – ibocus Nov 13 '19 at 13:27

1 Answers1

0

I have been able to resolve the issue, i needed to added the as.numeric when converting categorical values to numerical values

ibocus
  • 45
  • 1
  • 9