[英]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.