【发布时间】:2020-08-12 03:30:34
【问题描述】:
这是我在 R 中的随机森林和 rfsrc 代码;无论如何在我的 R 代码中包含 n_estimators 和 max_depth 之类的 sklearn 版本?另外,我怎样才能像这样绘制 OBB 误差与树的数量?
set.seed(2234)
tic("Time to train RFSRC fast")
fast.o <- rfsrc.fast(Label ~ ., data = train[(1:50000),],forest=TRUE)
toc()
print(fast.o)
#print(vimp(fast.o)$importance)
set.seed(2367)
tic("Time to test RFSRC fast ")
#data(breast, package = "randomForestSRC")
fast.pred <- predict(fast.o, test[(1:50000),])
toc()
print(fast.pred)
set.seed(3)
tic("RF model fitting without Parallelization")
rf <-randomForest(Label~.,data=train[(1:50000),])
toc()
print(rf)
plot(rf)
varImp(rf,sort = T)
varImpPlot(rf, sort=T, n.var= 10, main= "Variable Importance", pch=16)
rf_pred <- predict(rf, newdata=test[(1:50000),])
confMatrix <- confusionMatrix(rf_pred,test[(1:50000),]$Label)
confMatrix
感谢您的宝贵时间。
【问题讨论】:
-
这不是一个编程论坛,所以我担心你的问题跑题了。 sklearn 所称的
n_estimators被称为ntree。 rfsrc 有一个nodedepth参数来控制深度。
标签: r machine-learning python random-forest