本文へ移動
cccskills
無料GitHub で公開

tidymodels

R machine learning with tidymodels: recipes (preprocessing), parsnip (model specs), workflows (fit pipelines), tune (hyperparameters), rsample (resampling). Engines: ranger (RF), glmnet (lasso/ridge), xgboost, kknn. Model interpretation (permutation importance, PDP/ICE, SHAP via DALEX/iml/kernelshap) and fairness assessment (fairmodels). UMAP via uwot. Use when execution language is R. Python equivalent: scikit-learn. For econometric regression use fixest or r-stats.

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daafスター 238(GitHub 238 + cccskills 0)

実行スコア 未検証

インストール方法を見る

含まれるファイル(13)

  • SKILL.md19.5 KB
  • references/engines.md9.3 KB
  • references/evaluation.md6.2 KB
  • references/fairness.md7.1 KB
  • references/gotchas.md9.6 KB
  • references/interpretation.md9.5 KB
  • references/models.md7.8 KB
  • references/quickstart.md5.4 KB
  • references/recipes.md7.2 KB
  • references/resampling.md5.2 KB
  • references/tuning.md7.4 KB
  • references/unsupervised.md6.2 KB
  • references/workflows.md5.2 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

tidymodels Skill

R machine learning with the tidymodels ecosystem. Covers recipes for preprocessing (normalization, dummy encoding, imputation, interactions), parsnip for model specifications (linear_reg, logistic_reg, rand_forest, boost_tree, nearest_neighbor), workflows for combining recipe + model into a single fit/predict pipeline, tune for hyperparameter optimization via grid search and cross-validation, rsample for resampling (v-fold CV, bootstrap, LOO), and yardstick for evaluation metrics (rmse, accuracy, roc_auc, confusion matrix). Engines: ranger (random forest), glmnet (lasso/ridge/elasticnet), xgboost (gradient boosting), kknn (k-nearest neighbors). Also covers model interpretation (permutation importance, PDP/ICE, SHAP via DALEX, iml, and kernelshap) and fairness assessment (fairmodels). UMAP via uwot (not part of tidymodels). Use when execution language is R and the task involves classification, prediction, clustering via recipes, or preprocessing for ML. Python equivalent: scikit-learn. For econometric regression (OLS, FE, IV, DiD) use fixest or r-stats.

Comprehensive skill for machine learning in R with tidymodels. Covers supervised methods (classification, regression), preprocessing (recipes), hyperparameter tuning, resampling, evaluation, and unsupervised dimension reduction. Use decision trees below to find the right guidance, then load detailed references.

What is tidymodels?

tidymodels (Kuhn & Wickham) is R's unified machine learning framework, designed as the successor to caret:

  • Recipe/workflow paradigm: Preprocessing (recipe) and model (parsnip spec) are separate objects combined into a workflow -- different from scikit-learn's Pipeline where steps are positional
  • Engine abstraction: set_engine() decouples model type from implementation (e.g., rand_forest() |> set_engine("ranger") vs set_engine("randomForest"))
  • Tidy evaluation: Results come back as tibbles, not custom S3/S4 objects
  • Consistent interface: Every model uses fit(), predict(), augment() -- same verbs regardless of engine
  • Resampling first: Cross-validation and bootstrap are built into the tuning workflow, not bolted on

Version Notes

This skill targets tidymodels 1.4.1 (R 4.5.3). Key package versions:

PackageVersionRole
recipes1.3.2Preprocessing step definitions
parsnip1.5.0Model specifications + engine bindings
workflows1.3.0Recipe + model bundling
tune2.0.1Hyperparameter tuning infrastructure
rsample1.3.2Resampling (CV, bootstrap, etc.)
yardstick1.4.0Evaluation metrics
dials1.4.3Parameter ranges for tuning
ranger0.18.0Random forest engine
glmnet4.1-10Regularized regression engine
xgboost3.2.1.1Gradient boosting engine
kknn1.4.1K-nearest neighbors engine
uwot0.2.4UMAP (not tidymodels, standalone)
vip0.4.5Variable importance plots
DALEX2.5.3Model interpretation framework
iml0.11.4Model interpretation framework
kernelshap0.9.1Kernel SHAP
fairmodels1.2.2Fairness assessment

How to Use This Skill

Reference File Structure

Each topic in ./references/ contains focused documentation:

FilePurposeWhen to Read
quickstart.mdFull tidymodels workflow: recipe, model spec, workflow, fit, predictFirst use of tidymodels
recipes.mdstep_normalize, step_dummy, step_impute_*, step_interact, rolesPreprocessing tasks
models.mdparsnip model specs: linear_reg, logistic_reg, rand_forest, boost_tree, nearest_neighborChoosing and configuring models
workflows.mdworkflow() + add_recipe + add_model, fit(), predict(), augment()Building ML pipelines
tuning.mdtune(), tune_grid(), collect_metrics(), select_best(), finalize_workflowHyperparameter optimization
resampling.mdvfold_cv, bootstraps, loo_cv, group_vfold_cv, strata, assessment/analysisCreating resamples
engines.mdranger, glmnet, xgboost, kknn: engine-specific args, installation, tuning paramsEngine configuration
unsupervised.mdPCA via recipes::step_pca, UMAP via uwot::umap(), k-means via stats::kmeansDimension reduction, clustering
evaluation.mdyardstick metrics: rmse, accuracy, roc_auc, conf_mat, metric_set()Evaluating model performance
interpretation.mdPermutation importance, PDP/ICE, SHAP via DALEX/iml/kernelshap, vip, native engine importanceExplaining model predictions
fairness.mdfairness_check() via fairmodels + DALEX, yardstick group metrics, reweight/roc_pivot mitigationFairness assessment of classifiers
gotchas.mdRecipe baking order, data leakage, parsnip mode, engine args, tidymodels vs caretDebugging common mistakes

Reading Order

  1. New to tidymodels? Start with quickstart.md then workflows.md
  2. Need preprocessing? Read recipes.md
  3. Choosing a model? Read models.md then engines.md
  4. Need tuning? Read tuning.md then resampling.md
  5. Evaluating results? Read evaluation.md
  6. Explaining predictions or feature importance? Read interpretation.md
  7. Fairness assessment? Read fairness.md
  8. Unsupervised task? Read unsupervised.md
  9. Coming from scikit-learn? Read quickstart.md then gotchas.md
  10. Having issues? Check gotchas.md first

Related Skills

SkillRelationship
scikit-learnPython equivalent -- Pipeline/estimator pattern vs tidymodels recipe/workflow pattern. Load when execution language is Python.
data-scientistMethodology guidance -- load for "when and why" behind methods
r-python-translationCross-language mappings for R tidymodels vs Python scikit-learn
fixestEconometric regression with FE/IV/DiD in R. Use instead of tidymodels for causal inference.
r-statsBase R stats for OLS/GLM without FE. Use instead of tidymodels for simple regression without regularization or tuning.
ggplot2Visualization of model results. tidymodels objects are tidy -- pipe directly to ggplot2.

Routing guidance:

  • For econometric regression (hypothesis testing, standard errors, coefficient interpretation), use fixest or r-stats -- not tidymodels
  • For unsupervised methodology (when to cluster, how to validate), read exploratory-unsupervised.md in the data-scientist skill
  • For simple OLS/GLM without tuning or regularization, use r-stats
  • For data manipulation, use tidyverse

Quick Decision Trees

"I need to build a predictive model"

What kind of prediction?
+-- Continuous outcome (regression)
|   +-- Simple linear --> linear_reg() (./references/models.md)
|   +-- Regularized (lasso/ridge) --> linear_reg(penalty, mixture) with glmnet
|   |   (./references/models.md + ./references/engines.md)
|   +-- Tree-based --> rand_forest() or boost_tree()
|   |   (./references/models.md)
|   +-- Need to tune hyperparameters --> ./references/tuning.md
|   +-- NOTE: For econometric regression (causal inference, SEs),
|       use fixest or r-stats instead
+-- Categorical outcome (classification)
|   +-- Binary --> logistic_reg() (./references/models.md)
|   +-- Multi-class --> multinom_reg() or rand_forest()
|   |   (./references/models.md; logistic_reg() is binary-only)
|   +-- Best performance --> boost_tree() with xgboost
|   |   (./references/models.md + ./references/engines.md)
|   +-- Need tuning --> ./references/tuning.md

"I need to preprocess data"

What preprocessing?
+-- Normalize numeric features --> step_normalize() (./references/recipes.md)
+-- Create dummy variables --> step_dummy() (./references/recipes.md)
+-- Handle missing values --> step_impute_mean/median/knn (./references/recipes.md)
+-- Create interactions --> step_interact() (./references/recipes.md)
+-- PCA / dimension reduction --> step_pca() (./references/unsupervised.md)
+-- Mixed types (numeric + categorical) --> recipe with multiple steps
|   (./references/recipes.md)
+-- Feature engineering --> step_mutate(), step_log() (./references/recipes.md)

"I need to evaluate a model"

What evaluation?
+-- Regression metrics
|   +-- RMSE, MAE, R-squared --> ./references/evaluation.md
+-- Classification metrics
|   +-- Accuracy, ROC-AUC, confusion matrix --> ./references/evaluation.md
|   +-- Precision, recall, F1 --> ./references/evaluation.md
+-- Cross-validated performance
|   +-- collect_metrics() from tune_grid --> ./references/tuning.md
+-- Compare multiple models
|   +-- collect_metrics() + bind_rows --> ./references/evaluation.md

"I need to interpret a model or assess fairness"

What do I need?
+-- Feature importance (permutation, model-agnostic) --> DALEX model_parts()
|   or iml FeatureImp (./references/interpretation.md)
+-- Feature importance (engine-native, fast) --> ranger/xgboost importance + vip
|   (./references/interpretation.md; ranger needs importance= in set_engine)
+-- Feature effects (PDP / ICE) --> DALEX model_profile() or iml FeatureEffect
|   (./references/interpretation.md)
+-- SHAP values --> kernelshap (many rows) or predict_parts/Shapley (single row)
|   (./references/interpretation.md)
+-- Fairness metrics by protected group --> fairmodels fairness_check()
|   (./references/fairness.md)
+-- NOTE: methodology (when to interpret, causal caveats, fairness criteria)
    --> data-scientist skill: supervised-ml.md

"I need to tune hyperparameters"

Tuning approach?
+-- Grid search (exhaustive) --> tune_grid() (./references/tuning.md)
+-- Which parameters to tune --> tune() placeholder + dials ranges
|   (./references/tuning.md)
+-- Select best model --> select_best() + finalize_workflow()
|   (./references/tuning.md)
+-- Resampling for tuning --> vfold_cv() (./references/resampling.md)

"I need unsupervised analysis"

What unsupervised method?
+-- PCA (within a recipe) --> step_pca() (./references/unsupervised.md)
+-- UMAP --> uwot::umap() (./references/unsupervised.md)
+-- K-means clustering --> stats::kmeans() (./references/unsupervised.md)
+-- NOTE: tidymodels focuses on supervised learning. For advanced
    clustering, see data-scientist skill methodology guidance.

"Something isn't working"

Common issues?
+-- "recipe must be prepped" --> ./references/gotchas.md
+-- "set mode" error --> ./references/gotchas.md
+-- Engine-specific args not working --> ./references/gotchas.md
+-- Predictions wrong type --> ./references/gotchas.md
+-- Data leakage concerns --> ./references/gotchas.md
+-- tidymodels vs caret migration --> ./references/gotchas.md

File-First Execution in Research Workflows

Important: In DAAF research pipelines, tidymodels analyses are executed through script files, not interactively. This ensures auditability and reproducibility.

The pattern:

  1. Write ML code to scripts/stage8_analysis/{step}_{task-name}.R
  2. Execute via Bash with automatic output capture wrapper script
  3. Validation results get automatically embedded in scripts as comments
  4. If failed, create versioned copy for fixes

Closely read agent_reference/SCRIPT_EXECUTION_REFERENCE.md for the mandatory file-first execution protocol covering complete code file writing, output capture, and file versioning rules. All ML scripts must follow the Inline Audit Trail (IAT) standard -- see agent_reference/INLINE_AUDIT_TRAIL.md. For ML code, document model selection rationale (why this algorithm, why these hyperparameters, what assumptions) with # INTENT:, # REASONING:, and # ASSUMES: comments.

See:

  • agent_reference/WORKFLOW_PHASE4_ANALYSIS.md -- Stage 8 (Analysis & Visualization)
  • agent_reference/INLINE_AUDIT_TRAIL.md -- IAT documentation standard

The examples below show tidymodels syntax. In research workflows, wrap them in scripts following the file-first pattern.


Quick Reference

Essential Setup

library(tidymodels)       # Loads recipes, parsnip, workflows, tune, rsample, yardstick, dials
library(arrow)            # For parquet I/O (DAAF convention)

The tidymodels Workflow (5 Steps)

# 1. Define recipe (preprocessing)
rec <- recipe(outcome ~ ., data = train_data) |>
  step_normalize(all_numeric_predictors()) |>
  step_dummy(all_nominal_predictors())

# 2. Define model specification
spec <- rand_forest(trees = 500) |>
  set_engine("ranger") |>
  set_mode("classification")

# 3. Bundle into workflow
wf <- workflow() |>
  add_recipe(rec) |>
  add_model(spec)

# 4. Fit
fit <- wf |> fit(data = train_data)

# 5. Predict
preds <- fit |> predict(new_data = test_data)

Common Operations

OperationCode
Create reciperecipe(y ~ ., data = df)
Normalize numericstep_normalize(all_numeric_predictors())
Dummy encodestep_dummy(all_nominal_predictors())
Impute missingstep_impute_median(all_numeric_predictors())
Random forestrand_forest(trees = 500) |> set_engine("ranger")
Logistic regressionlogistic_reg() |> set_engine("glm")
Lassolinear_reg(penalty = 0.01, mixture = 1) |> set_engine("glmnet")
Ridgelinear_reg(penalty = 0.01, mixture = 0) |> set_engine("glmnet")
XGBoostboost_tree(trees = 500) |> set_engine("xgboost")
Build workflowworkflow() |> add_recipe(rec) |> add_model(spec)
Fit workflowwf |> fit(data = train_data)
Predictfit |> predict(new_data = test_data)
Augmentfit |> augment(new_data = test_data)
V-fold CVvfold_cv(train_data, v = 10, strata = outcome)
Tune gridtune_grid(wf, resamples = folds, grid = 20)
Best paramsselect_best(tune_results, metric = "rmse")
Finalizefinalize_workflow(wf, best_params)
RMSErmse(results, truth = y, estimate = .pred)
Accuracyaccuracy(results, truth = y, estimate = .pred_class)
ROC AUCroc_auc(results, truth = y, .pred_class1)
Confusion matrixconf_mat(results, truth = y, estimate = .pred_class)

Topic Index

TopicReference File
First tidymodels workflow./references/quickstart.md
recipe + spec + workflow pattern./references/quickstart.md
fit() and predict()./references/quickstart.md
train/test split./references/quickstart.md
step_normalize./references/recipes.md
step_dummy./references/recipes.md
step_impute_mean / median / knn./references/recipes.md
step_interact./references/recipes.md
step_mutate / step_log./references/recipes.md
Role assignment (update_role)./references/recipes.md
prep() and bake()./references/recipes.md
Selector functions./references/recipes.md
linear_reg./references/models.md
logistic_reg./references/models.md
multinom_reg (multiclass)./references/models.md
rand_forest./references/models.md
boost_tree./references/models.md
nearest_neighbor./references/models.md
set_engine()./references/models.md
set_mode()./references/models.md
workflow() construction./references/workflows.md
add_recipe / add_model./references/workflows.md
fit() on workflow./references/workflows.md
predict() on workflow./references/workflows.md
augment()./references/workflows.md
extract_fit_parsnip./references/workflows.md
tune() placeholder./references/tuning.md
tune_grid()./references/tuning.md
collect_metrics()./references/tuning.md
select_best()./references/tuning.md
finalize_workflow()./references/tuning.md
show_best()./references/tuning.md
dials parameter ranges./references/tuning.md
grid_space_filling / grid types./references/tuning.md
Parallel tuning (future backend)./references/tuning.md
vfold_cv./references/resampling.md
bootstraps./references/resampling.md
loo_cv./references/resampling.md
group_vfold_cv./references/resampling.md
strata argument./references/resampling.md
analysis() / assessment()./references/resampling.md
initial_split / training / testing./references/resampling.md
initial_validation_split / validation_set./references/resampling.md
ranger (random forest)./references/engines.md
glmnet (lasso / ridge / elasticnet)./references/engines.md
xgboost (gradient boosting)./references/engines.md
kknn (k-nearest neighbors)./references/engines.md
Engine-specific arguments./references/engines.md
PCA via step_pca./references/unsupervised.md
UMAP via uwot./references/unsupervised.md
K-means via stats::kmeans./references/unsupervised.md
rmse, mae, rsq./references/evaluation.md
accuracy, precision, recall, f_meas./references/evaluation.md
roc_auc, roc_curve./references/evaluation.md
conf_mat./references/evaluation.md
metric_set()./references/evaluation.md
Permutation importance (DALEX / iml)./references/interpretation.md
PDP / ICE plots./references/interpretation.md
SHAP (kernelshap, predict_parts, Shapley)./references/interpretation.md
vip / engine-native importance./references/interpretation.md
fairness_check (fairmodels)./references/fairness.md
Group-wise yardstick metrics./references/fairness.md
Fairness mitigation (reweight, roc_pivot)./references/fairness.md
Recipe baking order./references/gotchas.md
Data leakage in recipes./references/gotchas.md
parsnip mode requirement./references/gotchas.md
Engine-specific args (set_engine)./references/gotchas.md
tidymodels vs caret./references/gotchas.md
Prediction type (.pred vs .pred_class)./references/gotchas.md

Citation

When this framework is used as a primary analytical tool, include in the report's Software & Tools references:

Kuhn, M. & Wickham, H. (2020). Tidymodels: a collection of packages for modeling and machine learning using tidyverse principles. https://www.tidymodels.org

Cite when: tidymodels is used for model fitting, preprocessing, tuning, or evaluation central to the analysis. Do not cite when: Only loaded but no modeling performed.

For engine-specific citations:

Wright, M.N. & Ziegler, A. (2017). "ranger: A Fast Implementation of Random Forests for High Dimensional Data in C++ and R." Journal of Statistical Software, 77(1), 1-17. (ranger engine)

Friedman, J., Hastie, T., & Tibshirani, R. (2010). "Regularization Paths for Generalized Linear Models via Coordinate Descent." Journal of Statistical Software, 33(1), 1-22. (glmnet engine)

Chen, T. & Guestrin, C. (2016). "XGBoost: A Scalable Tree Boosting System." Proceedings of the 22nd ACM SIGKDD, 785-794. (xgboost engine)

For method-specific citations, consult the reference files in this skill and agent_reference/CITATION_REFERENCE.md.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。URL は 2 つまでです。

0 / 1000 文字

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

同じリポジトリのスキル

Guide for creating DAAF agent definition files. Covers 12-section template, hook registration, skills-in-frontmatter, integration checklist. Use when adding or revising agents. For SKILL.md files, use skill-authoring instead.

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daaf2382026年10月17日 更新

Researcher-facing analytic triangulation ("creative verification") for stress-testing provisional findings and designing pre-specified challenges before an analysis runs. Turns a researcher's concern or focal claim into competing explanations, bounded discriminating tests, audited diagnostic artifacts, and evidence-calibrated interpretations in a hypothesis/evidence ledger — behavioral, output-level verification replacing line-by-line code review. Covers 12 challenge families organized by Shadish-Cook-Campbell validity type, named sensitivity statistics, pre-committed interpretation rules, anti-fishing guardrails, and interactive diagnostic-artifact QA. Use in Ad Hoc Collaboration to verify, challenge, or stress-test a result, or to design discriminating tests before an analysis runs. Not code-change verification (verify skill / code review) and not final adjudication or re-execution (data-verifier, Reproducibility Verification) — prospective, hypothesis-driven challenge design of analytic claims.

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daaf2382026年10月17日 更新

In-situ smoke testing that verifies a LIVE DAAF deployment functions end-to-end in whatever provider route it is configured for. Auto-detects the active install route (anthropic-subscription, openrouter, chatgpt-subscription shim, openai-api shim) and runs tiered probes: Tier 0 free preflight (route/env coherence, hooks, statuslines, shim health); Tier 1 one live round-trip (~cents); Tier 2 a six-probe functional battery (dispatch, coding, web, skill loading, isolation-strip, nested-dispatch deny); Tier D a zero-cost deterministic battery (bats, Pester, lint, safety-hook tests). Use after install, after a rebuild or update, after any provider/config change (new API key, model remap, shim change), for pre-release validation, or when asked "is my install working" or to "smoke test the deployment/config." Requires the DAAF_DEV=1 dev image; a contributor tool, not end-user-facing. NOT DAAFBench (model behavioral-adherence evaluation under benchmarks/) and NOT scripts/smoke_tests/ (R/Python library-package smoke tests).

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daaf2382026年10月17日 更新

Operational framework for the DAAF orchestrator. Defines engagement modes, confirmation protocol, subagent dispatch, context budget, and reference-loading. Loaded exclusively by the orchestrator — not for subagents or user questions.

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daaf2382026年10月17日 更新

Data science methodology and method-selection routing for quantitative research. Covers EDA, data validation, descriptive analysis, causal inference (IV, DiD, RD, synthetic control), clustering/PCA/UMAP, supervised ML, geospatial analysis, network analysis, and visualization design. Contains the canonical method-to-library routing tree, routed by execution language — Python: statsmodels (OLS/GLM/time series), pyfixest (FE/DiD), linearmodels (RE/GMM/SUR), svy (complex surveys), scikit-learn (clustering/prediction ML), geopandas (spatial), igraph (network analysis); R: r-stats (OLS/GLM/time series), fixest (FE/DiD), plm (panel/RE/IV), survey-r (complex surveys), tidymodels (ML), sf-terra (spatial), igraph-r (network analysis). Load the routed tool-specific skill before giving tool-specific advice or writing code — library skills encode environment constraints and curated caveats absent from general knowledge.

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daaf2382026年10月17日 更新

Interpretation guidance for Urban Institute Education Data Portal datasets. The Portal is a curation layer over federal data: lowercase variable names, integer-encoded categoricals, standardized missing codes (-1 missing, -2 not applicable, -3 suppressed). Covers year definitions, grade encoding (grade=-1 is Pre-K, not missing), suppression rates, ODC-By licensing, and cross-source join identifiers. Load before analyzing any Portal data. Routes to source-specific deep-dive skills for individual datasets.

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daaf2382026年10月17日 更新

DAAF-Contribution-Community のスキルをすべて見る

このスキルの問題を報告する