How gust99-glitch/capstone_mortgage-project works
1. This repository is a Python data pipeline and analysis toolkit for HMDA mortgage data, focused on North Carolina from 2019–2024. The core architecture is a staged ETL flow: fetch raw public data, standardize it, apply stricter cleaning, then run analysis/modeling on the resulting dataset.
2. The ingestion boundary is mortgage.py. It connects to the FFIEC HMDA Data Browser API, downloads yearly CSVs, streams them with retry behavior, and keeps only a curated set of loan, borrower, geography, and census-tract columns. This script is the main bridge from external data service to local storage.
3. The first persisted layer is per-year cleaned data plus a combined annual file under data_hmda_nc/ (gitignored). The combined dataset is the handoff point between raw acquisition and downstream analytics. merge_datasets.py likely supports or duplicates the combine step, but the repo’s documented pipeline treats this as part of the ingestion/standardization layer.
4. data.py is the final data-conditioning stage. It reads the combined HMDA dataset and removes records that are not suitable for mortgage analysis: business/commercial loans, invalid demographic placeholders, invalid debt-to-income or conforming-limit values, and rows missing required fields. It writes the analysis-ready output to cleaned_data/nc_2019_2024_cleaned.csv.
5. The cleaned dataset is the central contract for the rest of the repository. Anything downstream should be treated as read-only consumers of that file, which keeps the boundary between data preparation and analysis fairly clean.
6. Several scripts are analysis/visualization consumers of that dataset, including LoanHeatmap.py, LoanvsInterestMap.py, and CompaniesHeapmapNC.py. These appear to generate exploratory charts or heatmaps, likely saved into the charts/ directory or related output folders.
7. action_taken_by_year_outputs/ and action_taken_distribution.csv are analysis artifacts rather than source code. They suggest a reporting layer focused on HMDA action outcomes over time, with yearly breakdowns and an aggregate distribution.
8. There is a separate modeling layer made up of lasso_selector.py, rf_model.py, and xgboost_model.py, with rankings.py and denied.py likely supporting feature ranking, lender comparisons, or denial analysis. Architecturally, this is an experimental ML tier built on top of the cleaned dataset, not part of the ingestion pipeline.
9. app.py and main.py are top-level entrypoints, but the repo is not organized like a single monolithic application. It looks more like a collection of runnable scripts for pipeline execution, plotting, and modeling, with each script owning one task.
10. Operationally, the repo is a local Python project managed with pyproject.toml, .python-version, and uv.lock, and it includes a workspace.ipynb notebook for ad hoc exploration. The key runtime dependency boundary is the FFIEC API; after that, everything is file-based CSV processing within the repository.
11. For an architecture diagram, the main flow is: FFIEC HMDA API → mortgage.py → yearly cleaned CSVs / combined NC dataset → data.py → final cleaned dataset → visualization scripts, reporting outputs, and ML experiments. The main storage boundaries are the two gitignored data directories plus chart/output folders.
Main entry points: mortgage.py mortgage · data.py data prep · pyproject.toml uv env · LoanHeatmap.py loan heatmap
Components 19
Ingestion
Fetches HMDA data and builds the raw/annual working dataset.
- FFIEC API · Public HMDA Data Browser API used as the upstream data source.
- mortgage · Downloads yearly HMDA CSVs, streams them with retries, and selects curated columns.
mortgage.py
Data prep
Combines and filters HMDA records into analysis-ready CSVs.
- merge data · Supports or duplicates the annual dataset merge/aggregation step.
merge_datasets.py - NC data · Gitignored per-year cleaned files and combined North Carolina HMDA dataset.
- data prep · Removes invalid loans and placeholder fields, producing the final cleaned dataset.
data.py - cleaned data · Final dataset consumed by analysis and modeling scripts.
Analysis
Exploratory charts, summaries, and reporting outputs from the cleaned dataset.
- loan heatmap · Generates exploratory loan distribution heatmaps.
LoanHeatmap.py - interest map · Maps loans against interest-rate related views.
LoanvsInterestMap.py - company heatmap · Produces lender/company-focused heatmaps for North Carolina.
CompaniesHeapmapNC.py - action outputs · Yearly and aggregate action-taken distribution CSV outputs.
action_taken_by_year_outputs - action dist · Aggregate action-taken distribution summary file.
action_taken_distribution.csv
Modeling
Experimental feature ranking and predictive modeling scripts.
- lasso selector · Linear modeling script for selecting informative features.
lasso_selector.py - random forest · Tree-based experimental model built on the cleaned dataset.
rf_model.py - xgboost model · Gradient-boosted experimental model built on the cleaned dataset.
xgboost_model.py - rankings · Supports feature or lender ranking workflows.
rankings.py - denied analysis · Supports denial-focused comparisons or reporting.
denied.py
Project runtime
Repository-level entrypoints and local execution environment.
- app entry · Top-level runnable script for one project workflow.
app.py - main entry · Top-level runnable script for one project workflow.
main.py - uv env · Local Python project/runtime configuration managed by uv and pyproject metadata.
pyproject.toml
Connections 19
- FFIEC API → mortgage: HMDA download · Mortgage ingestion pulls raw CSVs from the FFIEC service.
- mortgage → NC data: yearly CSVs · Fetched and curated data is written into the staged North Carolina dataset area.
- merge data → NC data: combine · Combines yearly data into a shared intermediate dataset.
- NC data → data prep: combined HMDA · Final conditioning stage reads the combined annual dataset.
- data prep → cleaned data: filtered output · Writes the analysis-ready cleaned CSV.
- cleaned data → loan heatmap: read-only input · Visualization scripts consume the cleaned dataset.
- cleaned data → interest map: read-only input · Visualization scripts consume the cleaned dataset.
- cleaned data → company heatmap: read-only input · Visualization scripts consume the cleaned dataset.
- cleaned data → lasso selector: train data · Modeling scripts build on the cleaned dataset.
- cleaned data → random forest: train data · Modeling scripts build on the cleaned dataset.
- cleaned data → xgboost model: train data · Modeling scripts build on the cleaned dataset.
- cleaned data → rankings: analysis input · Ranking utilities operate on the cleaned dataset or derived features.
- cleaned data → denied analysis: analysis input · Denial analysis operates on the cleaned dataset or derived features.
- loan heatmap → action outputs: exports · Some analyses write yearly distribution artifacts.
- interest map → action dist: summaries · Reporting layer produces aggregate action distribution outputs.
- app entry → mortgage: run pipeline · Top-level entrypoint can launch the ingestion workflow.
- main entry → data prep: run prep · Top-level entrypoint can launch the data-conditioning workflow.
- uv env → app entry: runtime · Project metadata and local environment support script execution.
- uv env → main entry: runtime · Project metadata and local environment support script execution.