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


R probably cal_validate_linear 使用和不使用線性回歸校準來測量性能

使用和不使用線性回歸校準來測量性能

用法

cal_validate_linear(
  .data,
  truth = NULL,
  estimate = dplyr::starts_with(".pred"),
  metrics = NULL,
  save_pred = FALSE,
  ...
)

# S3 method for resample_results
cal_validate_linear(
  .data,
  truth = NULL,
  estimate = dplyr::starts_with(".pred"),
  metrics = NULL,
  save_pred = FALSE,
  ...
)

# S3 method for rset
cal_validate_linear(
  .data,
  truth = NULL,
  estimate = dplyr::starts_with(".pred"),
  metrics = NULL,
  save_pred = FALSE,
  ...
)

參數

.data

rset 對象或帶有 .predictions 列的 tune::fit_resamples() 的結果。

truth

真實類別結果的列標識符(即一個因子)。這應該是一個不帶引號的列名。

estimate

列標識符向量,或 dplyr 選擇器函數之一,用於選擇哪些變量包含類概率。它默認為 tidymodels 使用的前綴 ( .pred_ )。標識符的順序將被視為與 truth 變量的級別順序相同。

metrics

通過 yardstick::metric_set() 創建的一組指標

save_pred

指示是否為 post-calibration 預測列。

...

要傳遞給 cal_estimate_logistic() 的選項,例如 smooth 參數。

性能指標

默認情況下,返回均方根誤差 (RMSE) 的平均值。可以使用任何適當的yardstick::metric_set()。驗證函數比較校準前後指標的平均值。

也可以看看

https://www.tidymodels.org/learn/models/calibration/, cal_estimate_linear()

例子

library(dplyr)
library(yardstick)
library(rsample)

head(boosting_predictions_test)
#> # A tibble: 6 × 2
#>   outcome .pred
#>     <dbl> <dbl>
#> 1   -4.65  4.12
#> 2    1.12  1.83
#> 3   14.7  13.1 
#> 4   36.3  19.1 
#> 5   14.1  14.9 
#> 6   -4.22  8.10

reg_stats <- metric_set(rmse, ccc)

set.seed(828)
boosting_predictions_oob %>%
  # Resample with 10-fold cross-validation
  vfold_cv() %>%
  cal_validate_linear(truth = outcome, smooth = FALSE, metrics = reg_stats)
#> #  10-fold cross-validation 
#> # A tibble: 10 × 4
#>    splits             id     .metrics         .metrics_cal    
#>    <list>             <chr>  <list>           <list>          
#>  1 <split [1800/200]> Fold01 <tibble [2 × 3]> <tibble [2 × 3]>
#>  2 <split [1800/200]> Fold02 <tibble [2 × 3]> <tibble [2 × 3]>
#>  3 <split [1800/200]> Fold03 <tibble [2 × 3]> <tibble [2 × 3]>
#>  4 <split [1800/200]> Fold04 <tibble [2 × 3]> <tibble [2 × 3]>
#>  5 <split [1800/200]> Fold05 <tibble [2 × 3]> <tibble [2 × 3]>
#>  6 <split [1800/200]> Fold06 <tibble [2 × 3]> <tibble [2 × 3]>
#>  7 <split [1800/200]> Fold07 <tibble [2 × 3]> <tibble [2 × 3]>
#>  8 <split [1800/200]> Fold08 <tibble [2 × 3]> <tibble [2 × 3]>
#>  9 <split [1800/200]> Fold09 <tibble [2 × 3]> <tibble [2 × 3]>
#> 10 <split [1800/200]> Fold10 <tibble [2 × 3]> <tibble [2 × 3]>
源代碼:R/cal-validate.R

相關用法


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