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


R probably int_conformal_cv 通過保形推理 CV+ 預測區間

可以使用 Barber 等人 (2018) 說明的 CV+ 保形推理方法來計算擬合回歸工作流對象的非參數預測區間。

用法

int_conformal_cv(object, ...)

# S3 method for default
int_conformal_cv(object, ...)

# S3 method for resample_results
int_conformal_cv(object, ...)

# S3 method for tune_results
int_conformal_cv(object, parameters, ...)

參數

object

來自 tidymodels 重采樣或調整函數的對象,例如 tune::fit_resamples()tune::tune_grid() 或類似函數。該對象的生成方式應使 .extracts 列包含每次重采樣的擬合工作流程(請參閱下麵的詳細信息)。

...

目前未使用。

parameters

調整參數值的小標題,可用於在處理之前過濾預測值。此 tibble 應從調整結果中選擇一組 hyper-parameter 值。僅當將調整對象傳遞給 object 時才需要這樣做。

"int_conformal_cv" 類的對象,包含創建間隔的信息。 predict() 方法用於生成間隔。

細節

該函數實現了 Barber at al (2018) 第 3 節中的 CV+ 方法。它使用重采樣模型擬合及其相關的保留殘差來為回歸模型製定預測區間。

該函數為計算準備對象。 predict() 方法計算新數據的間隔。

此方法是為 V-fold 交叉驗證(無重複)而開發的。對於任何其他重采樣方法,間隔覆蓋都是未知的。該函數不會停止其他類型重采樣的計算,但我們無法知道結果是否合適。

參考

Rina Foygel Barber、Emmanuel J. Candès、Aaditya Ramdas、Ryan J. Tibshirani“使用折刀+進行預測推理”,《統計年鑒》,49(1), 486-507, 2021

也可以看看

例子

library(workflows)
library(dplyr)
library(parsnip)
library(rsample)
library(tune)
library(modeldata)

set.seed(2)
sim_train <- sim_regression(200)
sim_new   <- sim_regression(  5) %>% select(-outcome)

sim_rs <- vfold_cv(sim_train)

# We'll use a neural network model
mlp_spec <-
  mlp(hidden_units = 5, penalty = 0.01) %>%
  set_mode("regression")

# Use a control function that saves the predictions as well as the models.
# Consider using the butcher package in the extracts function to have smaller
# object sizes

ctrl <- control_resamples(save_pred = TRUE, extract = I)

set.seed(3)
nnet_res <-
  mlp_spec %>%
  fit_resamples(outcome ~ ., resamples = sim_rs, control = ctrl)

nnet_int_obj <- int_conformal_cv(nnet_res)
nnet_int_obj
#> Conformal inference via CV+
#> preprocessor: formula 
#> model: mlp (engine = nnet) 
#> number of models: 10 
#> training set size: 200 
#> 
#> Use `predict(object, new_data, level)` to compute prediction intervals

predict(nnet_int_obj, sim_new)
#> # A tibble: 5 × 3
#>   .pred_lower   .pred .pred_upper
#>         <dbl>   <dbl>       <dbl>
#> 1        3.67 42.8           81.9
#> 2      -29.6   9.47          48.6
#> 3      -14.6  24.5           63.6
#> 4      -39.2  -0.0793        39.0
#> 5      -11.1  28.0           67.1

相關用法


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