当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R probably cal_plot_logistic 通过逻辑回归绘制概率校准图


逻辑回归模型适用于将原始结果数据用作结果,并将一类的估计类概率用作预测变量的情况。如果 smooth = TRUE ,则使用 mgcv::gam() 和默认平滑方法拟合广义加法模型。否则,使用简单的逻辑回归。

如果预测经过良好校准,拟合曲线应与对角线对齐。还显示了拟合线的置信区间。

用法

cal_plot_logistic(
  .data,
  truth = NULL,
  estimate = dplyr::starts_with(".pred"),
  conf_level = 0.9,
  smooth = TRUE,
  include_rug = TRUE,
  include_ribbon = TRUE,
  event_level = c("auto", "first", "second"),
  ...
)

# S3 method for data.frame
cal_plot_logistic(
  .data,
  truth = NULL,
  estimate = dplyr::starts_with(".pred"),
  conf_level = 0.9,
  smooth = TRUE,
  include_rug = TRUE,
  include_ribbon = TRUE,
  event_level = c("auto", "first", "second"),
  ...,
  .by = NULL
)

# S3 method for tune_results
cal_plot_logistic(
  .data,
  truth = NULL,
  estimate = dplyr::starts_with(".pred"),
  conf_level = 0.9,
  smooth = TRUE,
  include_rug = TRUE,
  include_ribbon = TRUE,
  event_level = c("auto", "first", "second"),
  ...
)

# S3 method for grouped_df
cal_plot_logistic(
  .data,
  truth = NULL,
  estimate = NULL,
  conf_level = 0.9,
  smooth = TRUE,
  include_rug = TRUE,
  include_ribbon = TRUE,
  event_level = c("auto", "first", "second"),
  ...
)

参数

.data

包含预测和概率列的未分组 DataFrame 对象。

truth

真实类别结果的列标识符(即一个因子)。这应该是一个不带引号的列名。

estimate

列标识符向量,或 dplyr 选择器函数之一,用于选择哪些变量包含类概率。它默认为 tidymodels 使用的前缀 ( .pred_ )。标识符的顺序将被视为与 truth 变量的级别顺序相同。

conf_level

可视化中使用的置信度。默认为 0.9。

smooth

通过 mgcv::gam()mgcv::s() 使用具有平滑项的广义加法模型作为预测器的逻辑。

include_rug

指示是否要包括地毯层的标志。默认为 TRUE 。在图中,顶部显示事件发生的频率,底部显示事件未发生的频率。

include_ribbon

指示是否要包含函数区层的标志。默认为 TRUE

event_level

单字符串。 "first" 或 "second" 指定将哪个真实级别视为 "event"。默认为"auto",它允许函数根据模型类型(二元、多类或线性)决定使用哪一个

...

传递给 tune_results 对象的其他参数。

.by

分组变量的列标识符。这应该是一个不带引号的列名称,用于选择用于分组的定性变量。默认为 NULL 。当.by = NULL时,不会进行分组。

一个 ggplot 对象。

也可以看看

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

cal_plot_breaks() , cal_plot_windowed()

例子


library(ggplot2)
library(dplyr)

cal_plot_logistic(
  segment_logistic,
  Class,
  .pred_good
)


cal_plot_logistic(
  segment_logistic,
  Class,
  .pred_good,
  smooth = FALSE
)

相关用法


注:本文由纯净天空筛选整理自Max Kuhn等大神的英文原创作品 Probability calibration plots via logistic regression。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。