# k-abhi1/predicting-age-from-brain-mri-features architecture

> Architecture diagram of the GitHub repository k-abhi1/predicting-age-from-brain-mri-features, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/k-abhi1/predicting-age-from-brain-mri-features
- Repository: https://github.com/k-abhi1/predicting-age-from-brain-mri-features

## Overview

##### Project type and purpose
- This is a machine-learning pipeline for **regression**: predicting a person’s age from precomputed brain MRI features.
- It focuses on data preprocessing (outliers, missing values), feature selection, model training, and generating a submission.

##### File structure
- Top-level folders:
- **data/** – CSV data files (X_train, y_train, X_test).
- **outlier_detection/** – code and plots for exploring/removing outliers.
- **archive/** – experimental scripts and previous model checkpoints.
- Key scripts:
- **outlier_detection/outlier_detection.py** – implements scaling, PCA, IsolationForest, and generates visualizations.
- **final.py** – combines the pipeline end-to-end and produces `submission.csv`.
- **archive/main.py** (legacy experiments).
- No dedicated “src” or “models” folder—everything is driven by final.py invoking routines from the outlier_detection module or archived scripts.

##### README for additional insights
- Describes a multi-stage pipeline:
- **Outlier Detection** with RobustScaler + PCA + IsolationForest
- **Missing-value Imputation** via KNNImputer
- **Feature Selection** (Mutual Information, correlation filters)
- **Modeling** (SVR, KNN, StackingRegressor)
- Lists major libraries: pandas, NumPy, scikit-learn, matplotlib/seaborn.

a. Main components
1. **Data Sources**
- Raw CSVs: X_train, y_train, X_test (data/)
2. **Outlier Detection Module**
- Scripts + plots (outlier_detection/)
- Sub-steps: scaling, PCA, IsolationForest
3. **Preprocessing & Imputation**
- RobustScaler / StandardScaler
- KNNImputer
4. **Feature Selection**
- Mutual Information selector
- Correlation filters
5. **Modeling**
- Base learners: SVR (RBF), KNeighborsRegressor
- Meta learner: SVR (linear) in a StackingRegressor
6. **Output/Submission**
- final.py generates `submission.csv`
b. Relationships and interactions
- Data flows from **Data Sources** → **Outlier Detection Module** → **Preprocessing & Imputation** → **Feature Selection** → **Modeling** → **Submission**.
- The **archive/** folder sits aside as “experiments history,” not on the main pipeline path.
c. Architectural patterns & principles
- **Linear pipeline**: each stage’s output is the next stage’s input.
- **Modular separation**: outlier_detection.py handles only outliers; final.py orchestrates the full pipeline.
- **Ensemble pattern**: stacking of multiple regressors.
d. Key technologies
- Python scripts orchestrate the flow.
- pandas/NumPy for data handling
- scikit-learn for scaling, imputation, PCA, outlier detection, feature selection, and models
- matplotlib/seaborn for plots in outlier_detection/

##### Essential details to capture
- Data inputs/outputs at each stage (e.g., raw vs. cleaned dataset sizes).
- The branch where visualization plots are generated in outlier_detection/.
- The two-level stacking structure within the modeling component.
- The final output: `submission.csv`.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Sources"
        X_train["X_train.csv"]:::data
        Y_train["y_train.csv"]:::data
        X_test["X_test.csv"]:::data
    end
    click X_train "https://github.com/k-abhi1/predicting-age-from-brain-mri-features/blob/main/data/X_train.csv"
    click Y_train "https://github.com/k-abhi1/predicting-age-from-brain-mri-features/blob/main/data/y_train.csv"
    click X_test "https://github.com/k-abhi1/predicting-age-from-brain-mri-features/blob/main/data/X_test.csv"

    Outlier_Detection["Outlier Detection Module"]:::data
    click Outlier_Detection "https://github.com/k-abhi1/predicting-age-from-brain-mri-features/blob/main/outlier_detection/outlier_detection.py"

    X_train --> Outlier_Detection
    Y_train --> Outlier_Detection
    X_test --> Outlier_Detection

    subgraph "Visualizations"
        Plots["Plots (PDFs)"]:::visualization
    end
    click Plots "https://github.com/k-abhi1/predicting-age-from-brain-mri-features/blob/main/outlier_detection/plots/*.pdf"

    Outlier_Detection --> Preprocessing
    Outlier_Detection --> Visualizations

    Preprocessing["Preprocessing & Imputation"]:::preprocessing
    click Preprocessing "https://github.com/k-abhi1/predicting-age-from-brain-mri-features/blob/main/final.py"

    Preprocessing --> Feature_Selection

    Feature_Selection["Feature Selection"]:::preprocessing
    click Feature_Selection "https://github.com/k-abhi1/predicting-age-from-brain-mri-features/blob/main/final.py"

    Feature_Selection --> SVR
    Feature_Selection --> KNN

    subgraph "Modeling"
        SVR["SVR (RBF)"]:::modeling
        KNN["KNN Regressor"]:::modeling
        SVR --> Meta
        KNN --> Meta
        Meta["Meta-Learner (SVR linear)"]:::modeling
    end
    click SVR "https://github.com/k-abhi1/predicting-age-from-brain-mri-features/blob/main/final.py"
    click KNN "https://github.com/k-abhi1/predicting-age-from-brain-mri-features/blob/main/final.py"
    click Meta "https://github.com/k-abhi1/predicting-age-from-brain-mri-features/blob/main/final.py"

    Meta --> Submission

    Submission["Submission Generation"]:::modeling
    click Submission "https://github.com/k-abhi1/predicting-age-from-brain-mri-features/blob/main/final.py"
    Submission --> SubmissionFile["submission.csv"]:::data

    subgraph "Archive Experiments (Legacy)"
        Main_py["main.py"]:::archive
        Best_cp["best_model.pth"]:::archive
    end
    click Main_py "https://github.com/k-abhi1/predicting-age-from-brain-mri-features/blob/main/archive/main.py"
    click Best_cp "https://github.com/k-abhi1/predicting-age-from-brain-mri-features/blob/main/archive/best_model.pth"

    classDef data fill:#E0F7FA,stroke:#006064;
    classDef preprocessing fill:#E8F5E9,stroke:#2E7D32;
    classDef modeling fill:#FFF3E0,stroke:#EF6C00;
    classDef visualization fill:#FFF8E1,stroke:#FF8F00;
    classDef archive fill:#F3E5F5,stroke:#6A1B9A;
```
