# ksy1022/predicting_the_performance_of_mlb_fa architecture

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

- Interactive diagram: https://gitdiagram.com/ksy1022/predicting_the_performance_of_mlb_fa
- Repository: https://github.com/ksy1022/predicting_the_performance_of_mlb_fa

## Overview

This is a research pipeline for predicting MLB free-agent performance from player statistics and contract data. The principal workflow assembles free-agent events and contracts with pre/post performance windows, creates hitter and pitcher datasets, trains two- and three-class classifiers, evaluates model and cutoff behavior, and produces research figures and tables. The README documents the overall pipeline; sampled source confirms selected dataset-building, model-labeling, and VIF behavior. Some subsystem links therefore rely on README documentation rather than inspected calls.

Main entry points: [`data/processed`](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/tree/main/data/processed) (Processed datasets), [`src/modeling/final_2_class_model.py`](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/modeling/final_2_class_model.py) (Two-class models), [`src/preprocessing/build_hitter_dataset.py`](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/build_hitter_dataset.py) (Hitter dataset), [`outputs`](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/tree/main/outputs) (Experiment results)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_collection["Data collection"]
  node_mlb_events["FA events"]
  node_mlb_stats["MLB statistics"]
  node_spotrac_merge["Contract merge"]
  node_spotrac_clean["Contract cleaning"]
  node_raw_data[("Raw inputs")]
end

subgraph group_prep["Dataset preparation"]
  node_fa_list["FA list<br/>[build_fa_list.py]"]
  node_interim_data[("Player windows")]
  node_processed_data[("Processed datasets")]
  node_hitter_dataset["Hitter dataset"]
  node_pitcher_dataset["Pitcher dataset"]
end

subgraph group_models["Modeling"]
  node_two_class["Two-class models"]
  node_three_class["Three-class models"]
  node_stack_features["Stacking features"]
end

subgraph group_evaluation["Evaluation"]
  node_vif_experiment["VIF experiments"]
  node_vif_handler["VIF selection"]
  node_vif_2class["VIF two-class"]
  node_vif_3class["VIF three-class"]
  node_cutoff_eval["Cutoff comparison"]
  node_three_cutoff_eval["Three-class cutoffs"]
  node_validation["Validation split"]
  node_outputs[("Experiment results")]
end

subgraph group_reporting["Reporting"]
  node_figures["Figures and tables"]
  node_figure_script["Figure generation<br/>[figure_mpl.py]"]
end

node_researcher(("Researcher"))

node_researcher -->|"runs collection"| node_mlb_events
node_researcher -->|"runs collection"| node_mlb_stats
node_researcher -->|"runs merge"| node_spotrac_merge
node_researcher -->|"runs cleaning"| node_spotrac_clean
node_mlb_events -->|"builds FA list"| node_fa_list
node_mlb_stats -->|"writes windows"| node_interim_data
node_spotrac_merge -->|"prepares contracts"| node_spotrac_clean
node_spotrac_clean -->|"writes contracts"| node_processed_data
node_fa_list -.->|"supports matching"| node_hitter_dataset
node_interim_data -->|"provides windows"| node_hitter_dataset
node_processed_data -->|"provides contracts"| node_hitter_dataset
node_interim_data -->|"provides windows"| node_pitcher_dataset
node_processed_data -->|"provides contracts"| node_pitcher_dataset
node_hitter_dataset -->|"writes hitter data"| node_processed_data
node_pitcher_dataset -->|"writes pitcher data"| node_processed_data
node_processed_data -->|"loads datasets"| node_two_class
node_processed_data -->|"loads datasets"| node_three_class
node_processed_data -->|"engineers features"| node_stack_features
node_two_class -.->|"writes metrics"| node_outputs
node_three_class -.->|"writes metrics"| node_outputs
node_vif_experiment -->|"applies selection"| node_vif_handler
node_vif_2class -->|"uses selection"| node_vif_handler
node_vif_3class -->|"uses selection"| node_vif_handler
node_vif_experiment -.->|"writes experiment results"| node_outputs
node_two_class -.->|"evaluates cutoffs"| node_cutoff_eval
node_three_class -.->|"evaluates cutoffs"| node_three_cutoff_eval
node_two_class -.->|"compares validation"| node_validation
node_outputs -->|"loads metrics"| node_figure_script
node_processed_data -->|"loads datasets"| node_figure_script
node_figure_script -.->|"creates figures"| node_figures

click node_mlb_events "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/collect_mlb_fa_events.py"
click node_mlb_stats "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/collect_mlb_stats.py"
click node_spotrac_merge "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/merge_spotrac_contracts.py"
click node_spotrac_clean "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/clean_spotrac_contracts.py"
click node_fa_list "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/build_fa_list.py"
click node_raw_data "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/tree/main/data/raw"
click node_interim_data "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/tree/main/data/interim/player_windows"
click node_processed_data "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/tree/main/data/processed"
click node_hitter_dataset "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/build_hitter_dataset.py"
click node_pitcher_dataset "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/build_pitcher_dataset.py"
click node_two_class "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/modeling/final_2_class_model.py"
click node_three_class "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/modeling/final_3_class_model.py"
click node_stack_features "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/feature_engineering/feature_engineering_stacking.py"
click node_vif_experiment "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/Multicollinearity/fa_experiment_vif.py"
click node_vif_handler "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/Multicollinearity/multicollinearity_handler.py"
click node_vif_2class "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/Multicollinearity/vif_2class_analysis.py"
click node_vif_3class "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/Multicollinearity/vif_3class_analysis.py"
click node_cutoff_eval "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/compare_2class_cutoffs.py"
click node_three_cutoff_eval "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/compare_3class_cutoffs.py"
click node_validation "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/fa_model_validation_split.py"
click node_outputs "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/tree/main/outputs"
click node_figures "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/tree/main/src/visualization"
click node_figure_script "https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/visualization/figure_mpl.py"

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_mlb_events,node_mlb_stats,node_spotrac_merge,node_spotrac_clean,node_raw_data toneBlue
class node_fa_list,node_interim_data,node_processed_data,node_hitter_dataset,node_pitcher_dataset toneAmber
class node_two_class,node_three_class,node_stack_features toneMint
class node_vif_experiment,node_vif_handler,node_vif_2class,node_vif_3class,node_cutoff_eval,node_three_cutoff_eval,node_validation,node_outputs toneRose
class node_figures,node_figure_script,node_researcher toneIndigo
```

## Components

### Data collection

- [FA events](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/collect_mlb_fa_events.py): `src/preprocessing/collect_mlb_fa_events.py`
- [MLB statistics](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/collect_mlb_stats.py): `src/preprocessing/collect_mlb_stats.py`
- [Contract merge](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/merge_spotrac_contracts.py): `src/preprocessing/merge_spotrac_contracts.py`
- [Contract cleaning](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/clean_spotrac_contracts.py): `src/preprocessing/clean_spotrac_contracts.py`
- [Raw inputs](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/tree/main/data/raw): `data/raw`

### Dataset preparation

- [FA list](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/build_fa_list.py): `src/preprocessing/build_fa_list.py`
- [Player windows](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/tree/main/data/interim/player_windows): `data/interim/player_windows`
- [Processed datasets](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/tree/main/data/processed): `data/processed`
- [Hitter dataset](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/build_hitter_dataset.py): `src/preprocessing/build_hitter_dataset.py`
- [Pitcher dataset](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/preprocessing/build_pitcher_dataset.py): `src/preprocessing/build_pitcher_dataset.py`

### Modeling

- [Two-class models](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/modeling/final_2_class_model.py): `src/modeling/final_2_class_model.py`
- [Three-class models](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/modeling/final_3_class_model.py): `src/modeling/final_3_class_model.py`
- [Stacking features](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/feature_engineering/feature_engineering_stacking.py): `src/feature_engineering/feature_engineering_stacking.py`

### Evaluation

- [VIF experiments](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/Multicollinearity/fa_experiment_vif.py): `src/evaluation/Multicollinearity/fa_experiment_vif.py`
- [VIF selection](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/Multicollinearity/multicollinearity_handler.py): `src/evaluation/Multicollinearity/multicollinearity_handler.py`
- [VIF two-class](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/Multicollinearity/vif_2class_analysis.py): `src/evaluation/Multicollinearity/vif_2class_analysis.py`
- [VIF three-class](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/Multicollinearity/vif_3class_analysis.py): `src/evaluation/Multicollinearity/vif_3class_analysis.py`
- [Cutoff comparison](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/compare_2class_cutoffs.py): `src/evaluation/compare_2class_cutoffs.py`
- [Three-class cutoffs](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/compare_3class_cutoffs.py): `src/evaluation/compare_3class_cutoffs.py`
- [Validation split](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/evaluation/fa_model_validation_split.py): `src/evaluation/fa_model_validation_split.py`
- [Experiment results](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/tree/main/outputs): `outputs`

### Reporting

- [Figures and tables](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/tree/main/src/visualization): `src/visualization`
- [Figure generation](https://github.com/ksy1022/predicting_the_performance_of_mlb_fa/blob/main/src/visualization/figure_mpl.py): `src/visualization/figure_mpl.py`

### Other components

- **Researcher**

## Connections

- Researcher → FA events: runs collection (evidence: `README.md`)
- Researcher → MLB statistics: runs collection (evidence: `README.md`)
- Researcher → Contract merge: runs merge (evidence: `README.md`)
- Researcher → Contract cleaning: runs cleaning (evidence: `README.md`)
- FA events → FA list: builds FA list (evidence: `README.md`)
- MLB statistics → Player windows: writes windows (evidence: `src/preprocessing/collect_mlb_stats.py`)
- Contract merge → Contract cleaning: prepares contracts (evidence: `README.md`)
- Contract cleaning → Processed datasets: writes contracts (evidence: `README.md`)
- FA list → Hitter dataset: supports matching
- Player windows → Hitter dataset: provides windows (evidence: `README.md`)
- Processed datasets → Hitter dataset: provides contracts (evidence: `README.md`)
- Player windows → Pitcher dataset: provides windows (evidence: `src/preprocessing/build_pitcher_dataset.py`)
- Processed datasets → Pitcher dataset: provides contracts (evidence: `src/preprocessing/build_pitcher_dataset.py`)
- Hitter dataset → Processed datasets: writes hitter data (evidence: `README.md`)
- Pitcher dataset → Processed datasets: writes pitcher data (evidence: `src/preprocessing/build_pitcher_dataset.py`)
- Processed datasets → Two-class models: loads datasets (evidence: `src/modeling/final_2_class_model.py`)
- Processed datasets → Three-class models: loads datasets (evidence: `src/modeling/final_3_class_model.py`)
- Processed datasets → Stacking features: engineers features (evidence: `src/feature_engineering/feature_engineering_stacking.py`)
- Two-class models → Experiment results: writes metrics
- Three-class models → Experiment results: writes metrics
- VIF experiments → VIF selection: applies selection (evidence: `src/evaluation/Multicollinearity/fa_experiment_vif.py`)
- VIF two-class → VIF selection: uses selection (evidence: `src/evaluation/Multicollinearity/vif_2class_analysis.py`)
- VIF three-class → VIF selection: uses selection (evidence: `src/evaluation/Multicollinearity/vif_3class_analysis.py`)
- VIF experiments → Experiment results: writes experiment results
- Two-class models → Cutoff comparison: evaluates cutoffs
- Three-class models → Three-class cutoffs: evaluates cutoffs
- Two-class models → Validation split: compares validation
- Experiment results → Figure generation: loads metrics (evidence: `src/visualization/figure_mpl.py`)
- Processed datasets → Figure generation: loads datasets (evidence: `src/visualization/figure_mpl.py`)
- Figure generation → Figures and tables: creates figures
