【问题标题】:XGboost and XGb.DMatrixXGboost 和 XGb.DMatrix
【发布时间】:2019-11-12 12:50:41
【问题描述】:

在 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)

【问题讨论】:

  • 你还有字符内幕training_set[-10],这就是为什么一切都转换为字符
  • 你好 StupidWolf,我已经能够解决这个问题,我需要在将分类值转换为数值时添加 as.numeric

标签: r rstudio xgboost xgbclassifier


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-04
    • 2017-03-14
    • 1970-01-01
    • 1970-01-01
    • 2016-10-20
    • 2017-03-22
    • 2018-02-04
    • 1970-01-01
    相关资源
    最近更新 更多