我想使用我的训练数据训练随机森林模型,但发生了一些错误。
错误信息如下:
Error in train.default(x, y, weights = w, ...) :
At least one of the class levels is not a valid R variable name; This will cause errors when class probabilities
are generated because the variables names will be converted to X1, X2, X3, X4, X5, X6, X7 . Please use factor
levels that can be used as valid R variable names (see ?make.names for help).
以下是我的代码:
rf.ctrl <- trainControl(method = "repeatedcv",
number = 10,
repeats = 10,
classProbs = TRUE,
summaryFunction = twoClassSummary)
set.seed(256)
#train the calssification model with random forest
rf.model <- train(as.factor(response) ~ .,data = trainvals,
method = "rf",
trControl = rf.ctrl,
tuneLength = 10,
metic = "ROC")
列车的结构是:
答案的等级为1,2,3,4,5,6和7。
答案 0 :(得分:0)
trainvals
数据框中的一个或多个列不是因子类型,因此会出现错误。您可以使用以下内容将所有列转换为因子:
trainvals[] <- lapply(trainvals, factor)