Download code/ampd/inspect.py from fryabcfry/cs4486-amp-pd-checkpoints: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/fryabcfry/cs4486-amp-pd-checkpoints/resolve/main/code/ampd/inspect.py
- Command line
-
hf download hf://fryabcfry/cs4486-amp-pd-checkpoints/code/ampd/inspect.py
-
curl -L -o inspect.py https://huggingface.co/fryabcfry/cs4486-amp-pd-checkpoints/resolve/main/code/ampd/inspect.py
1.61 kB
| """Data inspection without importing torch.""" | |
| from __future__ import annotations | |
| from pathlib import Path | |
| from typing import Any, Dict | |
| from .data.clinical import build_all_data | |
| from .data.splits import fold_summary, make_folds | |
| from .utils import ensure_dir, save_json | |
| def inspect_data(cfg: Dict[str, Any]) -> Dict[str, Any]: | |
| bundle = build_all_data(cfg) | |
| folds = make_folds(bundle.patients, cfg["cv"]) | |
| out = { | |
| "n_patients": int(len(bundle.patients)), | |
| "n_train_patients": int((bundle.patients["is_supplemental"] == 0).sum()), | |
| "n_samples_all": int(len(bundle.samples_all)), | |
| "n_samples_eval": int(len(bundle.samples_eval)), | |
| "n_features": int(len(bundle.feature_names)), | |
| "feature_names": list(bundle.feature_names), | |
| "target_cols": list(bundle.target_cols), | |
| "masks": {c: int(bundle.samples_eval[c].sum()) for c in bundle.mask_cols}, | |
| "cohorts": bundle.patients["cohort"].value_counts().to_dict(), | |
| "fold_summary": fold_summary(folds).to_dict(orient="records"), | |
| } | |
| out_dir = ensure_dir(Path(cfg["experiment"].get("output_dir", "runs")) / cfg["experiment"].get("name", "ampd_exp") / "inspect") | |
| save_json(out, out_dir / "data_summary.json") | |
| print(f"patients: {out['n_patients']} (train {out['n_train_patients']})") | |
| print(f"samples: all {out['n_samples_all']} | eval {out['n_samples_eval']}") | |
| print(f"features: {out['n_features']}") | |
| print(f"cohorts: {out['cohorts']}") | |
| print(f"masks: {out['masks']}") | |
| print(f"fold summary:\n{fold_summary(folds).to_string(index=False)}") | |
| return out | |