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


R probably cal_validate_isotonic 使用和不使用等滲回歸校準來測量性能

該函數使用重采樣來衡量校準預測值的效果。

用法

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

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

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

# S3 method for tune_results
cal_validate_isotonic(
  .data,
  truth = NULL,
  estimate = NULL,
  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 參數。

具有 .metrics_cal 列和附加 .predictions_cal 列(可選)的原始對象。還添加了cal_rset 類。

細節

這些函數旨在計算帶校準和不帶校準的性能。他們使用重采樣來衡量out-of-sample的有效性。有兩種方式傳遞數據:

  • 如果您有一個預測 DataFrame ,rset對象可以通過創建樣本函數。請參閱下麵的示例。

  • 如果您已經根據原始數據創建了重采樣對象並將其與 tune::fit_resamples() 一起使用,則可以將該對象傳遞給校準函數,它將使用相同的重采樣方案。如果應使用不同的重采樣方案,請在對象上運行 tune::collect_predictions() 並使用上一個要點中的過程。

請注意,這些函數不適用於tune_result 對象。 "validation"的概念意味著調整參數選擇已經解決。

collect_predictions() 可用於聚合指標以進行分析。

性能指標

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

也可以看看

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

例子


library(dplyr)

segment_logistic %>%
  rsample::vfold_cv() %>%
  cal_validate_isotonic(Class)
#> #  10-fold cross-validation 
#> # A tibble: 10 × 4
#>    splits            id     .metrics         .metrics_cal    
#>    <list>            <chr>  <list>           <list>          
#>  1 <split [909/101]> Fold01 <tibble [1 × 3]> <tibble [1 × 3]>
#>  2 <split [909/101]> Fold02 <tibble [1 × 3]> <tibble [1 × 3]>
#>  3 <split [909/101]> Fold03 <tibble [1 × 3]> <tibble [1 × 3]>
#>  4 <split [909/101]> Fold04 <tibble [1 × 3]> <tibble [1 × 3]>
#>  5 <split [909/101]> Fold05 <tibble [1 × 3]> <tibble [1 × 3]>
#>  6 <split [909/101]> Fold06 <tibble [1 × 3]> <tibble [1 × 3]>
#>  7 <split [909/101]> Fold07 <tibble [1 × 3]> <tibble [1 × 3]>
#>  8 <split [909/101]> Fold08 <tibble [1 × 3]> <tibble [1 × 3]>
#>  9 <split [909/101]> Fold09 <tibble [1 × 3]> <tibble [1 × 3]>
#> 10 <split [909/101]> Fold10 <tibble [1 × 3]> <tibble [1 × 3]>

源代碼:R/cal-validate.R

相關用法


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