# emzaro805/sba-loan-default-analysis architecture

> Architecture diagram of the GitHub repository emzaro805/sba-loan-default-analysis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/emzaro805/sba-loan-default-analysis
- Repository: https://github.com/emzaro805/sba-loan-default-analysis

## Overview

##### Main Components
- Data Sources:
- SampleData.csv (the dataset derived from the full SBA loan records)
- SBA Loan Data Driven Solution.docx (documentation/requirements reference)
- Data Ingestion & Preprocessing:
- R scripts (Project R code.R and Plot R code.R) that read the CSV, perform data cleaning (e.g., handling missing values, converting types), and prepare the data.
- Exploratory Data Analysis (EDA):
- Visualizations produced by ggplot2 in the R scripts (histograms, bar graphs, scatterplots to analyze distribution, loan default rates, etc.)
- Modeling & Analysis:
- Logistic Regression and K-Nearest Neighbors models – key components include feature selection and model evaluation (accuracy, Kappa Score) using libraries such as caret, dplyr, and e1071.
- Insights & Reporting:
- Generation of key insights and recommendations from the model output (as detailed in the README) that help banks adjust their loan approval processes.

##### Relationships and Data Flow
- Data flows from the raw dataset (CSV) to a data wrangling layer where missing values and irrelevant columns are handled.
- Cleaned data then flows into an EDA module where visualizations and statistical summaries are generated.
- Preprocessed data is passed into two parallel modeling components (Logistic Regression and KNN) which in turn feed into an evaluation layer that computes accuracy and other metrics.
- The outputs of the models lead to strategic recommendations documented in the README/docx report.

##### Architectural Patterns and Technologies
- Sequential processing steps: Ingestion → Cleaning → Exploration → Modeling → Evaluation → Reporting.
- R as the main programming environment, with key libraries (caret, ggplot2, dplyr, e1071, readxl) noted as supporting technologies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Sources"
        A["SampleData.csv"]:::datasource
        B["SBA Loan Data Driven Solution.docx"]:::datasource
    end

    C["Project R code.R\n(Data Ingestion & Cleaning)"]:::processing
    D["Plot R code.R\n(EDA & Visualization)"]:::processing

    subgraph "Model Training"
        E["Logistic Regression\n(caret, dplyr)"]:::modeling
        F["KNN\n(caret, dplyr, e1071)"]:::modeling
    end

    G{"Model Evaluation\n(Accuracy,Kappa)"}:::evaluation
    H["Insights & Reporting\n(README.md)"]:::reporting

    %% Data flow connections
    A -->|"ingests"| C
    B -->|"references"| C
    C -->|"prepares"| D
    D -->|"triggers"| E
    D -->|"triggers"| F
    E -->|"evaluates"| G
    F -->|"evaluates"| G
    G -->|"informs"| H

    %% Click Events
    click A "https://github.com/emzaro805/sba-loan-default-analysis/blob/main/SampleData.csv"
    click B "https://github.com/emzaro805/sba-loan-default-analysis/blob/main/SBA Loan Data Driven Solution.docx"
    click C "https://github.com/emzaro805/sba-loan-default-analysis/blob/main/Project R code.R"
    click D "https://github.com/emzaro805/sba-loan-default-analysis/blob/main/Plot R code.R"
    click H "https://github.com/emzaro805/sba-loan-default-analysis/blob/main/README.md"

    %% Styles
    classDef datasource fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef processing fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef modeling fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef evaluation fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef reporting fill:#ffeeba,stroke:#856404,stroke-width:2px;
```
