How vargezai/ms_capstone works
1. This repository is an offline, batch-style research pipeline rather than a service. The core architectural boundary is file-based: raw public datasets are transformed into processed CSVs, then consumed by separate analysis modules that each emit reproducible outputs under outputs/.
2. The ingestion layer lives in src/data_loader.py. It assembles a state-level monthly/annual panel from public government sources named in the README: EIA, EPA eGRID, NOAA, BEA, and DSIRE. Its main contract is the master dataset in data/processed/FINAL_MASTER_DATASET_2001_2026.csv, with a compact variant and summary statistics also written to data/processed/.
3. Data quality handling is split into a dedicated preprocessing stage in src/outlier_treatment.py. That stage takes the master dataset and produces FINAL_MASTER_DATASET_CLEAN.csv, plus an outlier log in outputs/EDA/. This is an important boundary because downstream analyses assume the cleaned dataset, not the raw master panel.
4. src/eda.py is a diagnostic subsystem, not part of the modeling path. It generates exploratory summaries and correlation/outlier artifacts into outputs/EDA/, giving a visibility layer over the dataset before the hypothesis-specific models run.
5. src/feature_engineering.py is the feature-construction boundary for predictive models. It derives the engineered feature table FINAL_MASTER_DATASET_FEATURES.csv, which is used primarily by BH3 and BH4. This module separates analytical feature preparation from inferential modeling.
6. BH1, implemented in src/panel_models.py, is the causal panel-econometrics branch. It runs TWFE and IV models, sensitivity checks, and dynamic panel robustness via Arellano-Bond GMM. Its outputs are tabular results in outputs/BH1/, intended for coefficient tables and robustness comparison rather than model deployment.
7. BH2, in src/did_causal_forest.py, is the staggered-treatment causal inference branch. It combines event-study DiD with causal forest estimation to produce ATT/CATE-style evidence and heterogeneity by state. The main artifacts are event-study and subgroup tables in outputs/BH2/.
8. BH3, in src/lstm_forecaster.py, is the time-series forecasting branch. It trains multi-horizon LSTM models for 1-, 3-, and 6-month forecasting, and includes Keras Tuner hyperparameter optimization. Artifacts include saved .keras models, tuner state, metrics, and prediction CSVs in outputs/BH3/. This branch is the most model-artifact-heavy and depends on TensorFlow/Keras and keras-tuner.
9. BH4, in src/xgboost_classifier.py, is the supervised classification/interpretability branch. It uses XGBoost plus SHAP to predict “top-decarbonizer” status and explain feature influence, including interaction analysis. Outputs include cross-validation metrics, predictions, feature importance tables, SHAP importance, and SHAP interaction matrices in outputs/BH4/.
10. BH5, in src/regional_analysis.py, is a subgroup econometrics branch that re-estimates RPS effects by Census region. It extends the causal panel logic to test heterogeneity across regions and writes region-specific interaction/results tables to outputs/BH5/.
11. The repository’s reporting layer is separate from the computation layer. docs/final_report.md, synopsis/, and docs/qm640_compliance_checklist.md consolidate results for submission, while the outputs/ directory stores the machine-generated evidence that feeds those reports.
12. In architectural terms, the project is organized around a single data lineage: raw files in data/raw/ → integrated master panel → cleaned panel → engineered feature table → five independent analysis branches → persisted outputs and report documents. The main design pattern is reproducible, stage-separated analysis with minimal coupling between hypotheses.
Main entry points: docs Reports · FINAL_MASTER_DATASET_CLEAN.csv Cleaned panel · data_loader.py Ingest panel · FINAL_MASTER_DATASET_2001_2026.csv Master panel
Components 23
Data pipeline
Raw inputs transformed into master, cleaned, and feature tables.
- Raw data · Public source files and incoming raw datasets.
data/raw - Ingest panel · Builds the state-level monthly/annual master panel from public sources.
src/data_loader.py - Master panel · Integrated master dataset used as the central analytic contract.
data/processed/FINAL_MASTER_DATASET_2001_2026.csv - Compact panel · Smaller processed variant of the master panel.
data/processed/FINAL_COMPACT_DATASET_2001_2026.csv - Summary stats · Processed summary statistics for the master dataset.
data/processed/SUMMARY_STATISTICS.csv - Clean panel · Cleans the master dataset and logs outliers for downstream use.
src/outlier_treatment.py - Cleaned panel · Downstream-ready dataset after outlier treatment.
data/processed/FINAL_MASTER_DATASET_CLEAN.csv - EDA checks · Generates exploratory summaries and correlation/outlier artifacts.
src/eda.py - EDA outputs · Exploratory tables and outlier logs.
outputs/EDA - Feature build · Derives engineered predictors for forecasting and classification.
src/feature_engineering.py - Feature table · Engineered feature dataset used mainly by BH3 and BH4.
data/processed/FINAL_MASTER_DATASET_FEATURES.csv
Analysis branches
Independent hypothesis and model branches consuming curated datasets.
- BH1 panel · TWFE, IV, sensitivity, and dynamic panel robustness analysis.
src/panel_models.py - BH2 causal forest · Event-study DiD and causal forest heterogeneity analysis.
src/did_causal_forest.py - BH3 LSTM · Multi-horizon LSTM forecasting with Keras Tuner optimization.
src/lstm_forecaster.py - BH4 XGBoost · XGBoost classification with SHAP interpretation and interactions.
src/xgboost_classifier.py - BH5 regions · Region-level re-estimation of policy effects and heterogeneity.
src/regional_analysis.py - BH1 outputs · Panel econometrics tables and robustness outputs.
outputs/BH1 - BH2 outputs · Event-study and subgroup causal inference tables.
outputs/BH2 - BH3 outputs · Saved models, tuning state, metrics, and predictions.
outputs/BH3 - BH4 outputs · Cross-validation, predictions, feature importance, and SHAP artifacts.
outputs/BH4 - BH5 outputs · Regional interaction and results tables.
outputs/BH5
Connections 27
- Raw data → Ingest panel: source files · Public raw datasets are ingested and harmonized.
- Ingest panel → Master panel: writes · Produces the master integrated panel.
- Ingest panel → Compact panel: writes · Produces a compact processed variant.
- Ingest panel → Summary stats: writes · Outputs summary statistics for the processed panel.
- Master panel → Clean panel: input · Cleaning stage consumes the master panel.
- Clean panel → Cleaned panel: writes · Produces the downstream-cleaned dataset.
- Clean panel → EDA outputs: logs · Outlier log is written into the EDA artifact space.
- Master panel → EDA checks: input · EDA inspects the master dataset.
- EDA checks → EDA outputs: writes · Generates exploratory summaries and correlation artifacts.
- Cleaned panel → Feature build: input · Feature construction starts from the cleaned panel.
- Feature build → Feature table: writes · Produces engineered features for modeling branches.
- Cleaned panel → BH1 panel: input · BH1 uses the cleaned panel for econometric estimation.
- Cleaned panel → BH2 causal forest: input · BH2 consumes the cleaned panel for causal inference.
- Feature table → BH3 LSTM: input · BH3 trains forecasting models on engineered features.
- Feature table → BH4 XGBoost: input · BH4 uses engineered features for classification and SHAP.
- Cleaned panel → BH5 regions: input · BH5 re-estimates effects by region from the cleaned panel.
- BH1 panel → BH1 outputs: writes · Exports tables and robustness results.
- BH2 causal forest → BH2 outputs: writes · Exports event-study and CATE/ATT evidence.
- BH3 LSTM → BH3 outputs: writes · Persists models, tuning artifacts, metrics, and predictions.
- BH4 XGBoost → BH4 outputs: writes · Exports performance, predictions, and SHAP artifacts.
- BH5 regions → BH5 outputs: writes · Exports regional interaction and results tables.
- BH1 outputs → Reports: feeds · BH1 evidence contributes to the report layer.
- BH2 outputs → Reports: feeds · BH2 evidence contributes to the report layer.
- BH3 outputs → Reports: feeds · BH3 evidence contributes to the report layer.
- BH4 outputs → Reports: feeds · BH4 evidence contributes to the report layer.
- BH5 outputs → Reports: feeds · BH5 evidence contributes to the report layer.
- Reports → Synopsis: summarizes · Narrative summary and submission materials consolidate results.