# jnr-10/oasis-alzheimers-ml architecture

> Architecture diagram of the GitHub repository jnr-10/oasis-alzheimers-ml, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jnr-10/oasis-alzheimers-ml
- Repository: https://github.com/jnr-10/oasis-alzheimers-ml

## Overview

1. **Repository purpose and split architecture**
   - This is a Python ML pipeline for OASIS-1 Alzheimer’s detection.
   - The codebase is organized into two main flows:
     - **Phase 1:** tabular-only clinical baseline.
     - **Phase 2:** enhanced pipeline that adds MRI-derived imaging biomarkers to the clinical features.

2. **Primary data sources**
   - Raw input comes from the OASIS-1 dataset, split across multiple disc folders (`oasis1-disc1` … `oasis1-disc12`) plus raw tabular exports under `data/raw/`.
   - `data/raw/combined_oasis.csv` appears to be the consolidated tabular dataset used by preprocessing.
   - Phase 2 consumes imaging feature CSVs in `data/enhanced_features/`, including the final merged dataset `oasis1_full_enhanced_features.csv`.

3. **Tabular preprocessing boundary**
   - `scripts/preprocess_oasis1.py` and `src/preprocessor.py` define the Phase 1 feature preparation boundary.
   - The key transformation called out in the README is **CDR-to-binary target conversion**: `CDR=0` becomes healthy, and `CDR>0` becomes dementia.
   - `src/data_loader.py` likely centralizes loading of the processed tabular splits and feature sets for training/evaluation.

4. **Imaging feature extraction subsystem**
   - The `src/imaging/` package is the main Phase 2 subsystem.
   - `io_utils.py` handles Analyze→NIfTI conversion, so the pipeline is not just ML; it also normalizes raw MRI file formats before feature extraction.
   - `qc.py` provides quality control checks, which is important because imaging pipelines are sensitive to corrupted or mismatched scans.
   - `merge_utils.py` suggests explicit safeguards around combining imaging outputs with clinical rows, likely preventing session/sample misalignment.

5. **MRI feature engineering flow**
   - `tissue_features.py` extracts global tissue metrics such as GM/WM/CSF volumes, fractions, ratios, and voxel counts.
   - `regional_features.py` extracts ROI-level biomarkers such as hippocampus, ventricles, entorhinal cortex, and temporal lobe measurements.
   - `atlas_utils.py` is the atlas-mapping layer, likely translating anatomical regions into indices/labels used by regional extraction.
   - The final Phase 2 feature space is described as **116 total features**: 12 clinical, 57 tissue, and 47 regional.

6. **Dataset assembly and feature manifests**
   - Phase 2 produces intermediate artifacts in `data/enhanced_features/`:
     - `full_imaging_manifest.csv`
     - `full_tissue_features.csv`
     - `full_regional_features.csv`
     - `oasis1_full_enhanced_features.csv`
   - This implies a staged pipeline: raw scans → extracted imaging feature tables → merged manifest/final dataset.
   - The manifest file is a useful architectural boundary because it likely tracks which disc/session/scan contributed to each row.

7. **Modeling subsystem**
   - `src/models.py` contains the 8-classifier model zoo: Random Forest, Logistic Regression, SVM, XGBoost, Gradient Boosting, KNN, Naive Bayes, and AdaBoost.
   - The training scripts are split by experiment stage:
     - `scripts/train_all_models.py` for Phase 1.
     - `scripts/train_phase2_enhanced.py` for Phase 2 and ablation variants.
   - The architecture is classic supervised classification rather than end-to-end deep learning.

8. **Evaluation and comparative experiments**
   - `scripts/evaluate.py` and `scripts/evaluate_all_models.py` support single-model and batch evaluation.
   - `scripts/compare_models.py` and `scripts/ablation_study.py` indicate a strong emphasis on model comparison and feature dependence analysis.
   - The key experimental branches in Phase 2 are:
     - full feature set,
     - no-MMSE variant,
     - imaging-only variant.

9. **Audit and reproducibility controls**
   - `scripts/pre_training_audit.py` is a distinct integrity gate before training the enhanced pipeline.
   - `src/imaging/qc.py` and `src/imaging/merge_utils.py` imply the repo treats data validity as part of the architecture, not just preprocessing noise.
   - `scripts/run_full_oasis1_pipeline.py` and `scripts/run_all_datasets.sh` suggest the pipeline is designed to be run end-to-end from raw inputs to final models.

10. **Artifacts and output boundaries**
   - Phase 1 outputs are organized under `data/processed/oasis1/` and corresponding model/result directories.
   - Phase 2 outputs are organized under `data/enhanced_features/` plus model/result folders for:
     - all features,
     - no MMSE,
     - imaging only.
   - The repo also includes a published report file, `PHASE2_CLINICAL_ACCURACY_REPORT.md`, which is part of the analysis deliverable rather than runtime code.

11. **Documentation and feature dictionary**
   - `docs/OASIS1_IMAGING_FEATURE_DICTIONARY.md` is an important schema reference for interpreting extracted biomarkers.
   - `docs/PROJECT_PROGRESS_REPORT.md` and the clinical accuracy report show that the repo tracks both technical and clinical performance outcomes.
   - For an architecture diagram, the documentation layer should sit alongside the pipeline because it defines feature semantics and experiment interpretation.

12. **Implementation footprint**
   - The project is a Python-based offline ML pipeline, driven mostly by scripts under `scripts/` and reusable modules under `src/`.
   - `requirements.txt` defines the runtime dependency boundary.
   - The system is batch-oriented: it ingests raw data, computes features, trains classical ML models, evaluates them, and writes CSV/model/report artifacts for later review.

Main entry points: [`scripts/run_full_oasis1_pipeline.py`](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/run_full_oasis1_pipeline.py) (Full run), [`scripts/train_phase2_enhanced.py`](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/train_phase2_enhanced.py) (Train phase2), [`src/imaging/qc.py`](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/imaging/qc.py) (QC), [`scripts/preprocess_oasis1.py`](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/preprocess_oasis1.py) (Prep script)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data"]
  node_raw_oasis[("Raw OASIS<br/>raw dataset")]
  node_combined_csv["Combined CSV<br/>tabular input<br/>[combined_oasis.csv]"]
  node_phase1_out[("Processed data<br/>artifact set")]
  node_enhanced_data[("Enhanced data<br/>feature tables")]
end

subgraph group_phase1["Phase 1"]
  node_phase1_proc["Preprocess<br/>tabular prep<br/>[preprocessor.py]"]
  node_phase1_script["Prep script<br/>entrypoint"]
  node_data_loader["Data loader<br/>dataset IO<br/>[data_loader.py]"]
end

subgraph group_phase2["Phase 2"]
  node_im_io["Format IO<br/>imaging IO<br/>[io_utils.py]"]
  node_im_qc["QC<br/>imaging audit<br/>[qc.py]"]
  node_atlas["Atlas map<br/>[atlas_utils.py]"]
  node_tissue["Tissue feats<br/>imaging features<br/>[tissue_features.py]"]
  node_regional["Regional feats<br/>imaging features"]
  node_merge["Merge<br/>[merge_utils.py]"]
end

subgraph group_ml["Modeling"]
  node_models["Model zoo<br/>classifiers<br/>[models.py]"]
  node_train_phase1["Train phase1<br/>training"]
  node_train_phase2["Train phase2<br/>training"]
  node_eval["Evaluate<br/>evaluation<br/>[evaluate.py]"]
  node_eval_all["Eval all<br/>benchmarking"]
  node_compare["Compare<br/>analysis<br/>[compare_models.py]"]
end

subgraph group_ops["Orchestration"]
  node_audit["Audit<br/>integrity gate"]
  node_runner["Full run<br/>pipeline runner"]
  node_dataset_runner["Batch run<br/>orchestration"]
end

subgraph group_docs["Docs"]
  node_feature_dict["Feature dict<br/>schema doc"]
  node_progress["Progress<br/>report"]
  node_clinical_report["Clinical report"]
end

node_raw_oasis -->|"consolidates"| node_combined_csv
node_combined_csv -->|"inputs"| node_phase1_script
node_phase1_script -->|"uses"| node_phase1_proc
node_phase1_proc -->|"writes"| node_phase1_out
node_phase1_out -->|"loads"| node_data_loader
node_data_loader -->|"feeds"| node_train_phase1
node_train_phase1 -->|"fits"| node_models
node_models -->|"scores"| node_eval
node_eval -->|"batch mode"| node_eval_all
node_raw_oasis -->|"scan normalizes"| node_im_io
node_im_io -->|"checks"| node_im_qc
node_im_qc -->|"validates"| node_atlas
node_atlas -->|"maps"| node_regional
node_im_qc -->|"approves"| node_tissue
node_tissue -->|"produces"| node_merge
node_regional -->|"produces"| node_merge
node_merge -->|"writes"| node_enhanced_data
node_enhanced_data -->|"audits"| node_audit
node_audit -->|"gates"| node_train_phase2
node_train_phase2 -->|"analyzes"| node_compare
node_compare -->|"benchmarks"| node_eval_all
node_runner -->|"orchestrates"| node_phase1_script
node_runner -->|"orchestrates"| node_audit
node_runner -->|"orchestrates"| node_train_phase2
node_dataset_runner -->|"repeats"| node_runner
node_feature_dict -->|"defines"| node_regional
node_feature_dict -->|"defines"| node_tissue
node_progress -.->|"tracks"| node_train_phase2
node_clinical_report -.->|"summarizes"| node_compare

click node_raw_oasis "https://github.com/jnr-10/oasis-alzheimers-ml/tree/main/data/raw"
click node_combined_csv "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/data/raw/combined_oasis.csv"
click node_phase1_proc "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/preprocessor.py"
click node_phase1_script "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/preprocess_oasis1.py"
click node_data_loader "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/data_loader.py"
click node_im_io "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/imaging/io_utils.py"
click node_im_qc "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/imaging/qc.py"
click node_atlas "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/imaging/atlas_utils.py"
click node_tissue "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/imaging/tissue_features.py"
click node_regional "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/imaging/regional_features.py"
click node_merge "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/imaging/merge_utils.py"
click node_enhanced_data "https://github.com/jnr-10/oasis-alzheimers-ml/tree/main/data/enhanced_features"
click node_models "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/models.py"
click node_train_phase1 "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/train_all_models.py"
click node_train_phase2 "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/train_phase2_enhanced.py"
click node_eval "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/evaluate.py"
click node_eval_all "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/evaluate_all_models.py"
click node_compare "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/compare_models.py"
click node_audit "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/pre_training_audit.py"
click node_runner "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/run_full_oasis1_pipeline.py"
click node_dataset_runner "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/run_all_datasets.sh"
click node_feature_dict "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/docs/OASIS1_IMAGING_FEATURE_DICTIONARY.md"
click node_progress "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/docs/PROJECT_PROGRESS_REPORT.md"
click node_clinical_report "https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/PHASE2_CLINICAL_ACCURACY_REPORT.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_raw_oasis,node_combined_csv,node_phase1_out,node_enhanced_data toneBlue
class node_phase1_proc,node_phase1_script,node_data_loader toneAmber
class node_im_io,node_im_qc,node_atlas,node_tissue,node_regional,node_merge toneMint
class node_models,node_train_phase1,node_train_phase2,node_eval,node_eval_all,node_compare toneRose
class node_audit,node_runner,node_dataset_runner toneIndigo
class node_feature_dict,node_progress,node_clinical_report toneTeal
```

## Components

### Data

Raw, staged, and enhanced CSV artifacts

- [Raw OASIS](https://github.com/jnr-10/oasis-alzheimers-ml/tree/main/data/raw): raw dataset · Source OASIS-1 disc folders and raw tabular exports feeding both phases · `data/raw`
- [Combined CSV](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/data/raw/combined_oasis.csv): tabular input · Consolidated clinical dataset used for preprocessing · `data/raw/combined_oasis.csv`
- **Processed data**: artifact set · Phase 1 processed dataset outputs used by downstream training
- [Enhanced data](https://github.com/jnr-10/oasis-alzheimers-ml/tree/main/data/enhanced_features): feature tables · Staged Phase 2 CSV artifacts including manifest, tissue, regional, and final merged datasets · `data/enhanced_features`

### Phase 1

Clinical/tabular baseline pipeline

- [Preprocess](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/preprocessor.py): tabular prep · Phase 1 clinical feature preparation and CDR-to-binary target conversion · `src/preprocessor.py`
- [Prep script](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/preprocess_oasis1.py): entrypoint · CLI entrypoint for OASIS-1 preprocessing · `scripts/preprocess_oasis1.py`
- [Data loader](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/data_loader.py): dataset IO · Loads processed splits and feature sets for training and evaluation · `src/data_loader.py`

### Phase 2

Clinical plus MRI-enhanced pipeline

- [Format IO](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/imaging/io_utils.py): imaging IO · Analyze-to-NIfTI conversion and scan normalization · `src/imaging/io_utils.py`
- [QC](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/imaging/qc.py): imaging audit · Quality-control checks on MRI inputs and extracted outputs · `src/imaging/qc.py`
- [Atlas map](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/imaging/atlas_utils.py): atlas mapping · Maps anatomical regions to labels and indices for ROI features · `src/imaging/atlas_utils.py`
- [Tissue feats](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/imaging/tissue_features.py): imaging features · Global GM/WM/CSF metrics, ratios, fractions, and voxel counts · `src/imaging/tissue_features.py`
- [Regional feats](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/imaging/regional_features.py): imaging features · ROI-level biomarkers such as hippocampus, ventricles, and entorhinal cortex · `src/imaging/regional_features.py`
- [Merge](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/imaging/merge_utils.py): feature merge · Aligns imaging outputs with clinical rows and guards against sample/session mismatch · `src/imaging/merge_utils.py`

### Modeling

Classical classifiers, training, and evaluation

- [Model zoo](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/src/models.py): classifiers · Classical supervised classifiers including RF, LR, SVM, XGBoost, GB, KNN, NB, and AdaBoost · `src/models.py`
- [Train phase1](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/train_all_models.py): training · Batch training for the clinical baseline experiment · `scripts/train_all_models.py`
- [Train phase2](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/train_phase2_enhanced.py): training · Enhanced training and ablation variants for the MRI-augmented pipeline · `scripts/train_phase2_enhanced.py`
- [Evaluate](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/evaluate.py): evaluation · Single-model and batch evaluation workflows · `scripts/evaluate.py`
- [Eval all](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/evaluate_all_models.py): benchmarking · Compares all candidate models across experiments · `scripts/evaluate_all_models.py`
- [Compare](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/compare_models.py): analysis · Model comparison and ablation analysis for Phase 2 variants · `scripts/compare_models.py`

### Orchestration

End-to-end runners and audit gates

- [Audit](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/pre_training_audit.py): integrity gate · Pre-training audit for enhanced pipeline data validity · `scripts/pre_training_audit.py`
- [Full run](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/run_full_oasis1_pipeline.py): pipeline runner · End-to-end OASIS-1 pipeline execution from raw inputs to final artifacts · `scripts/run_full_oasis1_pipeline.py`
- [Batch run](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/scripts/run_all_datasets.sh): orchestration · Runs the pipeline across datasets or experiment variants · `scripts/run_all_datasets.sh`

### Docs

Feature semantics and project reporting

- [Feature dict](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/docs/OASIS1_IMAGING_FEATURE_DICTIONARY.md): schema doc · Reference for imaging biomarker definitions and interpretation · `docs/OASIS1_IMAGING_FEATURE_DICTIONARY.md`
- [Progress](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/docs/PROJECT_PROGRESS_REPORT.md): report · Project progress and experiment tracking documentation · `docs/PROJECT_PROGRESS_REPORT.md`
- [Clinical report](https://github.com/jnr-10/oasis-alzheimers-ml/blob/main/PHASE2_CLINICAL_ACCURACY_REPORT.md): report · Published Phase 2 clinical accuracy report · `PHASE2_CLINICAL_ACCURACY_REPORT.md`

## Connections

- Raw OASIS → Combined CSV: consolidates · Raw dataset exports are consolidated into the tabular input
- Combined CSV → Prep script: inputs · Clinical CSV feeds Phase 1 preprocessing
- Prep script → Preprocess: uses · Script delegates feature preparation to preprocessing module
- Preprocess → Processed data: writes · Processed baseline data is stored for downstream training
- Processed data → Data loader: loads · Training and evaluation consume processed splits via loader
- Data loader → Train phase1: feeds · Loader provides datasets to baseline training
- Train phase1 → Model zoo: fits · Baseline script trains the model zoo
- Model zoo → Evaluate: scores · Evaluations consume model outputs and predictions
- Evaluate → Eval all: batch mode · Single-model evaluation and batch benchmarking are related workflows
- Raw OASIS → Format IO: scan normalizes · Raw MRI sources are normalized before feature extraction
- Format IO → QC: checks · Converted scans pass quality-control checks
- QC → Atlas map: validates · QC guards region mapping and downstream extraction assumptions
- Atlas map → Regional feats: maps · Atlas labels drive ROI feature extraction
- QC → Tissue feats: approves · Quality-checked imaging inputs are used for tissue metrics
- Tissue feats → Merge: produces · Global tissue features are merged into the Phase 2 table
- Regional feats → Merge: produces · Regional ROI features are merged into the Phase 2 table
- Merge → Enhanced data: writes · Merged imaging-clinical artifacts are persisted as staged CSVs
- Enhanced data → Audit: audits · Enhanced data is checked before training
- Audit → Train phase2: gates · Audit must pass before enhanced training proceeds
- Train phase2 → Compare: analyzes · Phase 2 training feeds comparison and ablation studies
- Compare → Eval all: benchmarks · Comparison relies on batch evaluation across models and variants
- Full run → Prep script: orchestrates · End-to-end runner invokes preprocessing
- Full run → Audit: orchestrates · Runner includes the pre-training audit gate
- Full run → Train phase2: orchestrates · Runner advances into enhanced training
- Batch run → Full run: repeats · Batch wrapper executes the full pipeline across datasets
- Feature dict → Regional feats: defines · Documentation describes region-level biomarkers
- Feature dict → Tissue feats: defines · Documentation describes tissue-level biomarkers
- Progress → Train phase2: tracks · Project progress documents the enhanced experiment status
- Clinical report → Compare: summarizes · Clinical report captures comparative Phase 2 findings
