[英]Can the out of bag error for a random forests model in R's TidyModel's framework be obtained?
If you directly use the ranger function, one can obtain the out-of-bag error from the resulting ranger class object.如果您直接使用游侠 function,则可以从生成的游侠 class object 中获得袋外错误。
If instead, one proceeds by way of setting up a recipe, model specification/engine, with tuning parameters, etc., how can we extract that same error?相反,如果通过设置配方、model 规范/引擎、调整参数等方式进行,我们如何提取同样的错误? The Tidymodels approach doesn't seem to hold on to that data.
Tidymodels 方法似乎没有保留这些数据。
If you want to access the ranger object inside of the parsnip object, it is there as $fit
:如果你想访问欧洲防风草 object 内的游侠 object,它是
$fit
:
library(tidymodels)
data("ad_data", package = "modeldata")
rf_spec <-
rand_forest() %>%
set_engine("ranger", oob.error = TRUE) %>%
set_mode("classification")
rf_fit <- rf_spec %>%
fit(Class ~ ., data = ad_data)
rf_fit
#> parsnip model object
#>
#> Fit time: 158ms
#> Ranger result
#>
#> Call:
#> ranger::ranger(x = maybe_data_frame(x), y = y, oob.error = ~TRUE, num.threads = 1, verbose = FALSE, seed = sample.int(10^5, 1), probability = TRUE)
#>
#> Type: Probability estimation
#> Number of trees: 500
#> Sample size: 333
#> Number of independent variables: 130
#> Mtry: 11
#> Target node size: 10
#> Variable importance mode: none
#> Splitrule: gini
#> OOB prediction error (Brier s.): 0.1340793
class(rf_fit)
#> [1] "_ranger" "model_fit"
class(rf_fit$fit)
#> [1] "ranger"
rf_fit$fit$prediction.error
#> [1] 0.1340793
Created on 2021-03-11 by the reprex package (v1.0.0)由代表 package (v1.0.0) 于 2021 年 3 月 11 日创建
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.