我使用随机森林进行预测,并且在predict(fit, test_feature)
行中出现以下错误。有人可以帮助我克服这一点。我对另一个数据集做了相同的步骤,没有发生错误。但我在这里得到错误。randomforest预测函数中的下标越界误差
Error: Error in x[, vname, drop = FALSE] : subscript out of bounds
training_index <- createDataPartition(shufflled[,487], p = 0.8, times = 1)
training_index <- unlist(training_index)
train_set <- shufflled[training_index,]
test_set <- shufflled[-training_index,]
accuracies<- c()
k=10
n= floor(nrow(train_set)/k)
for(i in 1:k){
sub1<- ((i-1)*n+1)
sub2<- (i*n)
subset<- sub1:sub2
train<- train_set[-subset, ]
test<- train_set[subset, ]
test_feature<- test[ ,-487]
True_Label<- as.factor(test[ ,487])
fit<- randomForest(x= train[ ,-487], y= as.factor(train[ ,487]))
prediction<- predict(fit, test_feature) #The error line
correctlabel<- prediction == True_Label
t<- table(prediction, True_Label)
}
我已经测试过我的火车和测试数据集。另外,当我为测试和测试数据运行独特(标签)时,我会得到相同的标签。我也检查了变量的名字,但仍然是相同的错误 –