inner-cv-tuning-discipline
Hyperparameter tuning uses 5-fold inner CV on the training set only; group-aware folds when cluster IDs are available.
- License 许可
- MIT
- 最近更新
- 2026-09-28
- Stars
- ★ 5
- Forks
- 0
01 前言 Front Matter
- name
- inner-cv-tuning-discipline
- layer
- methodology
- version
- 1.0
- priority
- 1
- resources
- []
- description
- Hyperparameter tuning uses 5-fold inner CV on the training set only; group-aware folds when cluster IDs are available.
- rule_severity
- mandatory
- trigger_keywords
- [ "tuning", "hyperparameter", "cv", "cross-validation", "gridsearch", "groupkfold" ]
- applicable_stages
- [ "Analyst", "Critic" ]
- references_skills
- []
- applicable_datasets
- []
- applicable_task_types
- []
03 SKILL.md 正文
Inner-CV Tuning Discipline
Hyperparameters are tuned via 5-fold inner cross-validation on the training set only. The test set is never touched during tuning — it exists solely for final evaluation reporting.
When cluster IDs (e.g., train_school_ids.csv) are available, the inner
CV must be group-aware to prevent within-cluster leakage during tuning.
Group-aware inner CV
from sklearn.model_selection import GroupKFold, StratifiedGroupKFold
from sklearn.model_selection import GridSearchCV
import pandas as pd
train_school_ids = pd.read_csv("train_school_ids.csv")["pseudo_school_id"].values
if is_classification:
inner_cv = StratifiedGroupKFold(n_splits=5, shuffle=True, random_state=42)
cv_splits = list(inner_cv.split(train_X, train_y, train_school_ids))
else:
inner_cv = GroupKFold(n_splits=5)
cv_splits = list(inner_cv.split(train_X, train_y, train_school_ids))
grid_search = GridSearchCV(
estimator,
param_grid,
cv=cv_splits,
scoring=scoring,
)
grid_search.fit(train_X, train_y)
If train_school_ids.csv does not exist, fall back to plain cv=5. The
Analyst should log a warning when this fallback is taken so reviewers
know clustering was not respected during tuning.
Hard rules
- Never use the test set during tuning, including for early-stopping
validation. Use a portion of the training set (e.g.,
validation_fraction=0.1inside MLP's built-in early stopping) when needed. - Random seed
random_state=42for every stochastic operation in tuning (CV shuffle, classifier initialization, GridSearchCV's internal randomization where applicable). - Refit on the full training set with the best hyperparameters before computing test-set metrics.
- No tuning grids on the test partition. The Critic will flag any evidence of test-set use during tuning as a critical issue.
Verification rules (Critic)
The Critic verifies via results.json metadata or warnings that:
- Tuning used training data only. If
results.warningsorresults.errorsmention test-set leakage during tuning → critical. - Tuning information is present for the tunable models (RF, XGBoost, ElasticNet, MLP). If absent → major (tuning should be documented in results metadata).
random_state=42was used (minor if missing).
Source provenance
Canonical source: agent_prompts/analyst.yaml §"Hyperparameter Tuning"
(complete code path with group-aware CV and the test-set-leakage
prohibition).
Merged content from:
data_registry/task_templates/prediction.yamlsubstepsmt_02throughmt_06and checkcheck_mt_train_only(workflow + verification language)data_registry/evaluation_rubrics/methodological_checklist.yamliteman_02(Critic verification)
04 同仓库更多 Skills
acm-fixture
Fixture writing skill for ACM acmart sigconf paper output.
prediction-fixture
Fixture skill for the prediction task type; references shap-fixture.
causal-fixture
Fixture skill for the causal_inference task type.
shap-fixture
Fixture methodology for SHAP feature importance analysis.
cluster-recon-fixture
Fixture methodology for reconstructing cluster IDs from fingerprint variables.
hsls09-fixture
Fixture skill for HSLS:09 with a bundled YAML resource and one cross-reference.