當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R tune show_best 研究最佳調整參數

show_best() 顯示排名靠前的 sub-models 及其性能估計。

用法

show_best(x, ...)

# S3 method for default
show_best(x, ...)

# S3 method for tune_results
show_best(x, metric = NULL, n = 5, ...)

select_best(x, ...)

# S3 method for default
select_best(x, ...)

# S3 method for tune_results
select_best(x, metric = NULL, ...)

select_by_pct_loss(x, ...)

# S3 method for default
select_by_pct_loss(x, ...)

# S3 method for tune_results
select_by_pct_loss(x, ..., metric = NULL, limit = 2)

select_by_one_std_err(x, ...)

# S3 method for default
select_by_one_std_err(x, ...)

# S3 method for tune_results
select_by_one_std_err(x, ..., metric = NULL)

參數

x

tune_grid()tune_bayes() 的結果。

...

對於 select_by_one_std_err()select_by_pct_loss() ,此參數直接傳遞給 dplyr::arrange() ,以便用戶可以對模型從最簡單到最複雜進行排序。也就是說,對於參數 p ,如果 p 的值較小表示模型較簡單,則傳遞不帶引號的表達式 p ;如果值較大表示模型較簡單,則傳遞 desc(p) 。這兩項函數至少需要一項。請參閱下麵的示例。

metric

將用於對模型進行排序的指標的字符值。 (有關更多詳細信息,請參閱https://yardstick.tidymodels.org/articles/metric-types.html)。如果 x 中存在單個指標,則不需要。如果有多個指標但沒有給出,則使用指標集中的第一個指標(並發出警告)。

n

要返回的頂部結果/行數的整數。

limit

可接受的性能損失限製(以百分比為單位)。請參閱下麵的詳細信息。

包含參數列的小標題。 show_best() 還包括性能指標列。

細節

select_best() 找到具有最佳性能值的調整參數組合。

select_by_one_std_err() 使用“one-standard 誤差規則”(Breiman _el at,1984),該規則選擇在數值最優結果的一個標準誤差範圍內的最簡單模型。

select_by_pct_loss() 選擇最簡單的模型,其性能損失在某個可接受的範圍內。

對於損失百分比,假設最佳模型的 RMSE 為 0.75,更簡單的模型的 RMSE 為 1。損失百分比為 (1.00 - 0.75)/1.00 * 100 或 25%。請注意,損失始終為非負數。

參考

布雷曼,利奧;弗裏德曼,J.H.;奧爾申,R.A.;斯通,C.J.(1984)。分類和回歸樹。加利福尼亞州蒙特雷:沃茲沃斯。

例子

data("example_ames_knn")

show_best(ames_iter_search, metric = "rmse")
#> # A tibble: 5 × 12
#>       K weight_func dist_power   lon   lat .metric .estimator   mean     n
#>   <int> <chr>            <dbl> <int> <int> <chr>   <chr>       <dbl> <int>
#> 1    33 triweight        0.511    10     3 rmse    standard   0.0728    10
#> 2     5 rank             0.411     2     7 rmse    standard   0.0740    10
#> 3    21 triweight        0.909    10     4 rmse    standard   0.0742    10
#> 4    21 cos              0.626     1     4 rmse    standard   0.0746    10
#> 5    19 inv              0.117     1     4 rmse    standard   0.0758    10
#> # ℹ 3 more variables: std_err <dbl>, .config <chr>, .iter <int>

select_best(ames_iter_search, metric = "rsq")
#> # A tibble: 1 × 6
#>       K weight_func dist_power   lon   lat .config              
#>   <int> <chr>            <dbl> <int> <int> <chr>                
#> 1    33 triweight        0.511    10     3 Preprocessor10_Model1

# To find the least complex model within one std error of the numerically
# optimal model, the number of nearest neighbors are sorted from the largest
# number of neighbors (the least complex class boundary) to the smallest
# (corresponding to the most complex model).

select_by_one_std_err(ames_grid_search, metric = "rmse", desc(K))
#> # A tibble: 1 × 13
#>       K weight_func dist_power   lon   lat .metric .estimator   mean     n
#>   <int> <chr>            <dbl> <int> <int> <chr>   <chr>       <dbl> <int>
#> 1    33 triweight        0.511    10     3 rmse    standard   0.0728    10
#> # ℹ 4 more variables: std_err <dbl>, .config <chr>, .best <dbl>,
#> #   .bound <dbl>

# Now find the least complex model that has no more than a 5% loss of RMSE:
select_by_pct_loss(
  ames_grid_search,
  metric = "rmse",
  limit = 5, desc(K)
)
#> # A tibble: 1 × 13
#>       K weight_func dist_power   lon   lat .metric .estimator   mean     n
#>   <int> <chr>            <dbl> <int> <int> <chr>   <chr>       <dbl> <int>
#> 1    33 triweight        0.511    10     3 rmse    standard   0.0728    10
#> # ℹ 4 more variables: std_err <dbl>, .config <chr>, .best <dbl>,
#> #   .loss <dbl>
源代碼:R/select_best.R

相關用法


注:本文由純淨天空篩選整理自Max Kuhn等大神的英文原創作品 Investigate best tuning parameters。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。