[英]Prediction using Random Forest in R
我在 R 中为我的 df 创建了一个 model 作为
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 它工作正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.