随机森林在R中的预测



我在R中为我的df创建了一个模型作为

fit <- randomForest(y ~ x1 + 
x2 + x3 + 
x4+ x5+x6+ x7+x8, 
data = data_train,ntree=35,
keep.forest=FALSE, importance=TRUE)

以形式给出结果

Call:
randomForest(formula = y ~ x1 + x2 
+      x3 + x4 + x5 + 
x6 +      x7 + x8, data = 
data_train, ntree = 35,      keep.forest = FALSE, importance = TRUE) 
Type of random forest: regression
Number of trees: 35
No. of variables tried at each split: 2
Mean of squared residuals: 2901510
% Var explained: 53.45

但是当我使用进行预测时

p <- predict(data_test, fit, type='prob')

显示错误

Error in ets(object, lambda = lambda, biasadj = biasadj, 
allow.multiplicative.trend = allow.multiplicative.trend,  : 
y should be a univariate time series

当我使用时

predict(fit, newdata= data_test)

显示错误

Error in predict.randomForest(fit, newdata = data_test) : 
No forest component in the object

我该怎么解决这个问题。。我是在R 中使用RandomForest的新手

如@bzki建议,将keep.forest=TRUE运行良好

相关内容

  • 没有找到相关文章

最新更新