Tidyposterior开源项目最佳实践
2025-05-20 05:51:18作者:柏廷章Berta
1、项目介绍
Tidyposterior 是一个基于 R 语言的包,用于进行模型的后续分析,特别是对于通过重采样生成的模型结果进行分析。该包利用贝叶斯广义线性模型来比较模型的表现,无需涉及测试集。Tidyposterior 可以与 rsample 对象一起使用,也可以用于任何以数据帧形式表示的结果。
2、项目快速启动
为了快速启动 Tidyposterior 项目,你需要安装 R 语言环境。以下是在 R 中安装和启动 Tidyposterior 的步骤:
# 安装 Tidyposterior
install.packages("tidyposterior")
# 加载必要的包
library(tidymodels)
library(tidyposterior)
# 加载数据集
data("two_class_dat", package = "modeldata")
# 设置随机种子
set.seed(100)
# 定义数据集的折叠
folds <- vfold_cv(two_class_dat)
# 定义模型
logistic_reg_glm_spec <- logistic_reg() %>% set_engine("glm")
mars_earth_spec <- mars(prod_degree = 1) %>% set_engine("earth") %>% set_mode("classification")
# 设置重采样控制
rs_ctrl <- control_resamples(save_workflow = TRUE)
# 拟合模型并收集结果
logistic_reg_glm_res <- logistic_reg_glm_spec %>% fit_resamples(Class ~ ., resamples = folds, control = rs_ctrl)
mars_earth_res <- mars_earth_spec %>% fit_resamples(Class ~ ., resamples = folds, control = rs_ctrl)
# 提取 ROC AUC 指标
logistic_roc <- collect_metrics(logistic_reg_glm_res, summarize = FALSE) %>%
dplyr::filter(.metric == "roc_auc") %>%
dplyr::select(id, logistic = .estimate)
mars_roc <- collect_metrics(mars_earth_res, summarize = FALSE) %>%
dplyr::filter(.metric == "roc_auc") %>%
dplyr::select(id, mars = .estimate)
# 合并结果
resamples_df <- full_join(logistic_roc, mars_roc, by = "id")
# 使用 perf_mod 进行模型比较
set.seed(101)
roc_model_via_df <- perf_mod(resamples_df, iter = 2000)
3、应用案例和最佳实践
应用案例:Tidyposterior 可以用于比较不同模型的性能。例如,你可以使用 Tidyposterior 来比较逻辑回归模型和 MARS 模型在 10 折交叉验证下的 ROC AUC 值。
最佳实践:为了获得可靠的比较结果,建议使用足够多的重采样迭代次数。此外,应确保模型和重采样过程在比较之前已经正确设置。
4、典型生态项目
Tidyposterior 是 tidymodels 套件的一部分,它与 rsample、broom、dplyr 等其他 R 包集成得很好,形成一个完整的模型开发和评估生态系统。这些包共同提供了一套统一的工具和最佳实践,帮助数据科学家和统计学家进行可重复的数据分析。
登录后查看全文
热门项目推荐
暂无数据
项目优选
收起
deepin linux kernel
C
27
11
OpenHarmony documentation | OpenHarmony开发者文档
Dockerfile
539
3.76 K
Ascend Extension for PyTorch
Python
349
414
本项目是CANN提供的数学类基础计算算子库,实现网络在NPU上加速计算。
C++
889
609
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
338
185
openJiuwen agent-studio提供零码、低码可视化开发和工作流编排,模型、知识库、插件等各资源管理能力
TSX
986
252
openGauss kernel ~ openGauss is an open source relational database management system
C++
169
233
暂无简介
Dart
778
193
华为昇腾面向大规模分布式训练的多模态大模型套件,支撑多模态生成、多模态理解。
Python
114
140
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
1.35 K
758