[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EKY70BCS2P4R3MWF4WAQ5D":3,"skill-same:01M6EKY70BCS2P4R3MWF4WAQ5D":73},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":29,"linkOnly":30,"markdownContent":31,"markdownBody":32,"frontMatter":33,"refName":50,"commitSha":51,"skillDirectory":52,"forksCount":53,"repositoryHtmlUrl":54,"repositoryHomepageUrl":6,"ownerHtmlUrl":55,"ownerBlogUrl":56,"ownerDescription":57,"updatedAt":58,"install":59,"resources":72},"01M6EKY70BCS2P4R3MWF4WAQ5D","school-aware-train-test-split",null,"Group-aware train\u002Ftest split that prevents cluster leakage when students are nested in schools (or analogous clustered units).","cgpan\u002Fedm-ars-public","cgpan","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F118746117?v=4","01M6EKT5TG36Q3GH340QN8RH08","Chenguang Pan","01M6EKT5YTQVRARGJF0VPA1SY7",5,"MIT","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Fskills\u002Fmethodology\u002Fschool-aware-train-test-split\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28],"test","train","train test split","school aware train test split","methodology","public","els","nested","units","cluster","2026-11-10 10:12:30",false,"---\nname: school-aware-train-test-split\nlayer: methodology\ndescription: Group-aware train\u002Ftest split that prevents cluster leakage when students are nested in schools (or analogous clustered units).\ntrigger_keywords:\n  - split\n  - train-test\n  - groupkfold\n  - stratifiedgroupkfold\n  - cluster\n  - nested\napplicable_task_types: []\napplicable_datasets:\n  - hsls09_public\n  - els_2002\napplicable_stages:\n  - DataEngineer\npriority: 1\nreferences_skills: []\nresources: []\nversion: \"1.0\"\nrule_severity: mandatory\n---\n\n# School-Aware Train\u002FTest Split\n\nWhen students are nested in schools (or any analogous clustered design),\na naive `train_test_split` lets the same school appear in both partitions.\nSchool-level features then leak from train to test and inflate every\nmetric. Use a group-aware split instead.\n\n## Pick the splitter by task type\n\n- **Classification** — `StratifiedGroupKFold(n_splits=5, shuffle=True,\n  random_state=42)`. Take fold 0 as the test set. Stratification preserves\n  the class ratio approximately while keeping every school inside one fold.\n- **Regression** — `GroupShuffleSplit(n_splits=1, test_size=0.2,\n  random_state=42)`.\n\nAlways wrap the call in `analysis_helpers.grouped_train_test_split()`\nrather than calling sklearn splitters directly. The helper enforces the\ngroup constraint, returns a `split_meta` dict for `data_report.json`, and\nfalls back gracefully when only one fold is feasible.\n\n```python\nimport analysis_helpers\n\ntrain_idx, test_idx, split_meta = analysis_helpers.grouped_train_test_split(\n    df=analytic_df,\n    y=analytic_df[outcome_variable],\n    groups=analytic_df[\"pseudo_school_id\"],\n    test_size=0.2,\n    stratify=(outcome_type in [\"binary\", \"categorical\"]),\n    random_state=42,\n)\n\ntrain_df = analytic_df.iloc[train_idx]\ntest_df = analytic_df.iloc[test_idx]\n```\n\n## Persist group IDs for downstream stages\n\nSave the cluster ID for each partition so the Analyst can use the same\ngroups for inner-CV and clustered bootstrap CIs:\n\n```python\nanalytic_df.iloc[train_idx][\"pseudo_school_id\"].to_csv(\n    \"train_school_ids.csv\", index=False, header=[\"pseudo_school_id\"]\n)\nanalytic_df.iloc[test_idx][\"pseudo_school_id\"].to_csv(\n    \"test_school_ids.csv\", index=False, header=[\"pseudo_school_id\"]\n)\n```\n\n## What to record in `data_report.json`\n\nAdd `split_meta` under key `\"split_info\"`:\n\n```json\n{\n  \"split_info\": {\n    \"split_method\": \"StratifiedGroupKFold\",\n    \"group_aware\": true,\n    \"n_groups_train\": 712,\n    \"n_groups_test\": 178,\n    \"group_overlap\": 0\n  }\n}\n```\n\n`group_overlap` MUST be `0`. Any non-zero value means a school appears in\nboth partitions and the split is invalid.\n\nAlso append the partial-multilevel acknowledgement to\n`data_report.warnings`:\n\n> Multilevel structure (students nested in schools) is partially addressed:\n> train\u002Ftest split is school-aware (no school in both sets) and clustered\n> bootstrap CIs account for within-school correlation. However, models do\n> not include school-level random effects.\n\n## Mandatory: pd.qcut requires `duplicates='drop'`\n\nIf you bin a continuous outcome to enable stratification (e.g., for\n`StratifiedGroupKFold` on a regression target), `pd.qcut` raises\n`ValueError: Bin edges must be unique` whenever the outcome\ndistribution has ties at quantile boundaries. This is common with\ndiscrete or near-discrete outcomes (Likert scales, GPAs, integer\ncounts) and with small samples, and the original DataEngineer code\nobserved in `regression\u002Fslim_problem_formulator_retry\u002F` crashed on\nexactly this. Always pass `duplicates='drop'`:\n\n```python\n# WRONG -- crashes on tied bin edges:\nstrat_bins = pd.qcut(y, q=10)\n\n# RIGHT -- drops duplicate edges, may produce fewer than q bins:\nstrat_bins = pd.qcut(y, q=10, duplicates='drop')\n\n# After binning, check that you got enough bins for stratification:\nif strat_bins.cat.categories.size \u003C 5:\n    # Too few bins to stratify usefully -- fall back to a non-stratified\n    # group split (GroupShuffleSplit) rather than failing silently.\n    train_idx, test_idx, split_meta = analysis_helpers.grouped_train_test_split(\n        df=analytic_df,\n        y=analytic_df[outcome_variable],\n        groups=analytic_df[\"pseudo_school_id\"],\n        test_size=0.2,\n        stratify=False,           # explicit fall-back\n        random_state=42,\n    )\n    split_meta[\"stratification_fallback_reason\"] = (\n        f\"qcut produced only {strat_bins.cat.categories.size} bins; \"\n        \"stratification skipped\"\n    )\n```\n\nThis rule is mandatory: a `pd.qcut` crash aborts the whole pipeline.\n\n## Verification rules (Critic)\n\nThe Critic verifies `data_report.split_info.group_overlap == 0` and that\nthe multilevel-limitation warning is present. Failure on either is a\nmajor issue.\n\n## Source provenance\n\nCanonical source: `agent_prompts\u002Fdata_engineer.yaml` §\"Step 7\"\n(complete code path with `analysis_helpers.grouped_train_test_split` and\nthe group-ID persistence).\n\nMerged content from:\n- `data_registry\u002Ftask_templates\u002Fprediction.yaml` substep `dp_09` and\n  check `check_dp_grouped_split` (workflow + verification language)\n\nThis skill is generic across nested-survey datasets; the cluster-ID\nsource (`pseudo_school_id`) is dataset-specific and is set up by a\ndataset-layer skill (`hsls09-school-cluster-reconstruction` for HSLS).\n","# School-Aware Train\u002FTest Split\n\nWhen students are nested in schools (or any analogous clustered design),\na naive `train_test_split` lets the same school appear in both partitions.\nSchool-level features then leak from train to test and inflate every\nmetric. Use a group-aware split instead.\n\n## Pick the splitter by task type\n\n- **Classification** — `StratifiedGroupKFold(n_splits=5, shuffle=True,\n  random_state=42)`. Take fold 0 as the test set. Stratification preserves\n  the class ratio approximately while keeping every school inside one fold.\n- **Regression** — `GroupShuffleSplit(n_splits=1, test_size=0.2,\n  random_state=42)`.\n\nAlways wrap the call in `analysis_helpers.grouped_train_test_split()`\nrather than calling sklearn splitters directly. The helper enforces the\ngroup constraint, returns a `split_meta` dict for `data_report.json`, and\nfalls back gracefully when only one fold is feasible.\n\n```python\nimport analysis_helpers\n\ntrain_idx, test_idx, split_meta = analysis_helpers.grouped_train_test_split(\n    df=analytic_df,\n    y=analytic_df[outcome_variable],\n    groups=analytic_df[\"pseudo_school_id\"],\n    test_size=0.2,\n    stratify=(outcome_type in [\"binary\", \"categorical\"]),\n    random_state=42,\n)\n\ntrain_df = analytic_df.iloc[train_idx]\ntest_df = analytic_df.iloc[test_idx]\n```\n\n## Persist group IDs for downstream stages\n\nSave the cluster ID for each partition so the Analyst can use the same\ngroups for inner-CV and clustered bootstrap CIs:\n\n```python\nanalytic_df.iloc[train_idx][\"pseudo_school_id\"].to_csv(\n    \"train_school_ids.csv\", index=False, header=[\"pseudo_school_id\"]\n)\nanalytic_df.iloc[test_idx][\"pseudo_school_id\"].to_csv(\n    \"test_school_ids.csv\", index=False, header=[\"pseudo_school_id\"]\n)\n```\n\n## What to record in `data_report.json`\n\nAdd `split_meta` under key `\"split_info\"`:\n\n```json\n{\n  \"split_info\": {\n    \"split_method\": \"StratifiedGroupKFold\",\n    \"group_aware\": true,\n    \"n_groups_train\": 712,\n    \"n_groups_test\": 178,\n    \"group_overlap\": 0\n  }\n}\n```\n\n`group_overlap` MUST be `0`. Any non-zero value means a school appears in\nboth partitions and the split is invalid.\n\nAlso append the partial-multilevel acknowledgement to\n`data_report.warnings`:\n\n> Multilevel structure (students nested in schools) is partially addressed:\n> train\u002Ftest split is school-aware (no school in both sets) and clustered\n> bootstrap CIs account for within-school correlation. However, models do\n> not include school-level random effects.\n\n## Mandatory: pd.qcut requires `duplicates='drop'`\n\nIf you bin a continuous outcome to enable stratification (e.g., for\n`StratifiedGroupKFold` on a regression target), `pd.qcut` raises\n`ValueError: Bin edges must be unique` whenever the outcome\ndistribution has ties at quantile boundaries. This is common with\ndiscrete or near-discrete outcomes (Likert scales, GPAs, integer\ncounts) and with small samples, and the original DataEngineer code\nobserved in `regression\u002Fslim_problem_formulator_retry\u002F` crashed on\nexactly this. Always pass `duplicates='drop'`:\n\n```python\n# WRONG -- crashes on tied bin edges:\nstrat_bins = pd.qcut(y, q=10)\n\n# RIGHT -- drops duplicate edges, may produce fewer than q bins:\nstrat_bins = pd.qcut(y, q=10, duplicates='drop')\n\n# After binning, check that you got enough bins for stratification:\nif strat_bins.cat.categories.size \u003C 5:\n    # Too few bins to stratify usefully -- fall back to a non-stratified\n    # group split (GroupShuffleSplit) rather than failing silently.\n    train_idx, test_idx, split_meta = analysis_helpers.grouped_train_test_split(\n        df=analytic_df,\n        y=analytic_df[outcome_variable],\n        groups=analytic_df[\"pseudo_school_id\"],\n        test_size=0.2,\n        stratify=False,           # explicit fall-back\n        random_state=42,\n    )\n    split_meta[\"stratification_fallback_reason\"] = (\n        f\"qcut produced only {strat_bins.cat.categories.size} bins; \"\n        \"stratification skipped\"\n    )\n```\n\nThis rule is mandatory: a `pd.qcut` crash aborts the whole pipeline.\n\n## Verification rules (Critic)\n\nThe Critic verifies `data_report.split_info.group_overlap == 0` and that\nthe multilevel-limitation warning is present. Failure on either is a\nmajor issue.\n\n## Source provenance\n\nCanonical source: `agent_prompts\u002Fdata_engineer.yaml` §\"Step 7\"\n(complete code path with `analysis_helpers.grouped_train_test_split` and\nthe group-ID persistence).\n\nMerged content from:\n- `data_registry\u002Ftask_templates\u002Fprediction.yaml` substep `dp_09` and\n  check `check_dp_grouped_split` (workflow + verification language)\n\nThis skill is generic across nested-survey datasets; the cluster-ID\nsource (`pseudo_school_id`) is dataset-specific and is set up by a\ndataset-layer skill (`hsls09-school-cluster-reconstruction` for HSLS).\n",{"name":5,"layer":23,"version":34,"priority":35,"resources":36,"description":7,"rule_severity":37,"trigger_keywords":38,"applicable_stages":43,"references_skills":45,"applicable_datasets":46,"applicable_task_types":49},"1.0",1,[],"mandatory",[39,40,41,42,28,26],"split","train-test","groupkfold","stratifiedgroupkfold",[44],"DataEngineer",[],[47,48],"hsls09_public","els_2002",[],"main","1aeaead66d2bf876109f3b101005d2eed54041d9","skills\u002Fmethodology\u002Fschool-aware-train-test-split",0,"https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public","https:\u002F\u002Fgithub.com\u002Fcgpan","https:\u002F\u002Fcpan.ai","Ph.D. candidate in Measurement, Evaluation, and Statistics.","2026-09-28 20:39:06",{"source":8,"skillName":5,"commands":60,"prompt":70,"zipAvailable":71},[61,64,67],{"tool":62,"command":63},"npx","npx skills add cgpan\u002Fedm-ars-public --skill school-aware-train-test-split",{"tool":65,"command":66},"bunx","bunx skills add cgpan\u002Fedm-ars-public --skill school-aware-train-test-split",{"tool":68,"command":69},"pnpm","pnpm dlx skills add cgpan\u002Fedm-ars-public --skill school-aware-train-test-split","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Fskills\u002Fmethodology\u002Fschool-aware-train-test-split\u002FSKILL.md",true,[],[74,87,101,110,122,132],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":29},"01M6EM1ZTQZVAP90DZTVBHCCFB","acm-fixture","Fixture writing skill for ACM acmart sigconf paper output.","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Fwriting\u002Facm-fixture\u002FSKILL.md",[],[81,82,83,84,85,86],"acm fixture","fixture","writing","LaTeX","writer","paper",{"skillNo":88,"name":89,"nameZh":6,"description":90,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":29},"01M6EM1XNFETAZFGPHQPAXKBYN","prediction-fixture","Fixture skill for the prediction task type; references shap-fixture.","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Ftask-type\u002Fprediction-fixture\u002FSKILL.md",[],[82,94,95,96,97,98,99,100],"prediction fixture","task","type","references","fixture skill","shap","analyst",{"skillNo":102,"name":103,"nameZh":6,"description":104,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":105,"categories":106,"keywords":107,"publishedAt":29},"01M6EM1V4MQXYGQ7K2ZDJRAPSM","causal-fixture","Fixture skill for the causal_inference task type.","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Ftask-type\u002Fcausal-fixture\u002FSKILL.md",[],[82,108,96,95,109,98],"causal fixture","inference",{"skillNo":111,"name":112,"nameZh":6,"description":113,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":114,"categories":115,"keywords":116,"publishedAt":29},"01M6EM1SCWFZZ2ACSAP65GNWK9","shap-fixture","Fixture methodology for SHAP feature importance analysis.","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Fmethodology\u002Fshap-fixture\u002FSKILL.md",[],[117,82,99,118,23,119,120,121],"shap fixture","feature importance","analysis","explainer","feature",{"skillNo":123,"name":124,"nameZh":6,"description":125,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":126,"categories":127,"keywords":128,"publishedAt":29},"01M6EM1PZC1MK1G0D1YFVYAQ9W","cluster-recon-fixture","Fixture methodology for reconstructing cluster IDs from fingerprint variables.","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Fmethodology\u002Fcluster-recon-fixture\u002FSKILL.md",[],[129,130,28,82,131,23],"recon","cluster recon fixture","ids",{"skillNo":133,"name":134,"nameZh":6,"description":135,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":136,"categories":137,"keywords":138,"publishedAt":29},"01M6EM1MZVKMSWEXZ7TJ45DS04","hsls09-fixture","Fixture skill for HSLS:09 with a bundled YAML resource and one cross-reference.","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Fdataset\u002Fhsls09-fixture\u002FSKILL.md",[],[82,139,140,24,141,98,142,129,28,143],"hsls09 fixture","yaml","reference","dataset","registry"]