Ter*_*ero 1 r predict random-forest
当我运行预测函数时,出现以下错误:
Error in predict.randomForest(fit, newdata = na.roughfix(csvTest[, -c(1:2, :
'prob' or 'vote' not meaningful for regression code here
Run Code Online (Sandbox Code Playgroud)
这是代码:
fit <- foreach (ntree = rep (round(number_trees/nc), nc),
.combine = combine, .packages = 'randomForest') %dopar% randomForest(y=csv$mal,x=na.roughfix (csv[, c(1:2,4:5,8:13,17,19:20,22:29,ncol(csv))]), ntree = number_trees)
prob <- predict (fit, newdata = na.roughfix (csvTest[, -c(1:2,4:5,8:13,17,19:20,22:29,ncol(csvTest))]), type = 'prob')[, 2]
Run Code Online (Sandbox Code Playgroud)
谁能帮助我了解问题所在?谢谢
我刚刚解决了。这是因为默认情况下,我的目标变量(csv $ mal)在应为“因子”的情况下(0或1)被R默认设置为“数字”。
对于数字,随机林以type =“ regression”而不是type =“ classification”运行。