# alirezaahmadibeni/bankruptcy-prediction architecture

> Architecture diagram of the GitHub repository alirezaahmadibeni/bankruptcy-prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alirezaahmadibeni/bankruptcy-prediction
- Repository: https://github.com/alirezaahmadibeni/bankruptcy-prediction

## Overview

##### Project type and purpose
- This is a Python-based data-science/ML research pipeline (targeting Python 2.7) that demonstrates and visualizes two meta-heuristic algorithms (Genetic Algorithm, Grey Wolf Optimization) for cluster-based undersampling and training of an Artificial Neural Network (ANN) to predict corporate bankruptcy.
- It is not a full-stack web app but rather a command-line/experimental framework with a clear sequence: data loading → sampling/optimization → model training → analysis/visualization.

##### File structure
Top-level files and directories:
- 1year.arff, xclara.csv – input datasets
- ann.py – code defining/controlling the ANN model and training routines
- ga/ – package containing GA logic (ga.py for core GA, crossover.py for operators)
- gwo/ – package containing Grey Wolf Optimization logic (gwo.py)
- main.py – orchestrator that ties data, sampling algorithms, ANN training, and evaluation together
- README.ME – project description and dataset info

##### Extract architecture hints from the README
- The README confirms the focus on “Optimization of cluster-based evolutionary undersampling for ANN” using GA and GWO.
- It references a UCI dataset for bankruptcy prediction, implying the data-loading module must handle ARFF/CSV.
- There is no mention of external services—this is a standalone pipeline.

##### Components & relationships
a. Main Components
1. Data Layer
- Raw data sources: 1year.arff, xclara.csv
- Preprocessing submodule (could live inside main.py or ann.py)
2. Sampling/Optimization Layer
- Genetic Algorithm package (ga/)
- Grey Wolf Optimization package (gwo/)
3. Modeling Layer
- Artificial Neural Network module (ann.py)
4. Orchestration Layer
- main.py – invokes data loading → runs each optimizer → retrains ANN → collects metrics
5. Visualization Layer
- plot_kmeans_silhouette_analysis.py (for cluster evaluation)
- Any plotting inside main.py or ann.py for training curves, performance metrics
6. Outputs
- Saved model performance metrics, cluster analysis plots, console logs

b. Relationships & data flow
- Data Layer → Preprocessing → passes cleaned data to Orchestration
- Orchestration (main.py) calls Sampling/Optimization Layer (GA and GWO)
- Each optimizer returns an “undersampled” dataset variant → passed to Modeling Layer
- Modeling Layer trains ANN on that variant → returns performance metrics
- Orchestration collects all metrics → passes to Visualization Layer → generates plots

c. Architectural patterns/design principles
- Modular packages for each algorithm (separation of concerns)
- A single orchestrator script to avoid tight coupling between modules
- Reusable data-loading/preprocessing for both GA and GWO paths
- Clear separation between algorithm logic and model training

d. Key technologies/frameworks
- Python 2.7
- NumPy, SciPy, scikit-learn (implied for clustering, silhouette analysis)
- matplotlib or seaborn (for plotting)
- Possibly liac-arff or similar for ARFF parsing

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Layer"
        RawARFF["1year.arff"]:::data
        RawCSV["xclara.csv"]:::data
    end

    RawARFF --> Preprocess
    RawCSV --> Preprocess

    Preprocess["Preprocessing Module\n(ann.py)"]:::data

    subgraph "Orchestration Layer"
        Main["main.py"]:::orchestration
    end

    Preprocess --> Main
    Main -. control flow .-> Preprocess

    subgraph "Sampling/Optimization Layer"
        GA["GA Module\n(ga/ga.py & ga/crossover.py)"]:::opt
        GWO["GWO Module\n(gwo/gwo.py)"]:::opt
    end

    Main --> GA
    Main --> GWO

    GA --> Model
    GWO --> Model

    subgraph "Modeling Layer"
        Model["ANN Module\n(ann.py)"]:::model
    end

    subgraph "Visualization Layer"
        Silhouette["Silhouette Analysis\n(plot_kmeans_silhouette_analysis.py)"]:::vis
        Performance["Training & Metrics Plots\n(ann.py & main.py)"]:::vis
    end

    GA --> Silhouette
    Model --> Performance
    Main --> Performance

    classDef data fill:#BBDEFB,stroke:#0D47A1
    classDef orchestration fill:#CFD8DC,stroke:#37474F
    classDef opt fill:#C8E6C9,stroke:#1B5E20
    classDef model fill:#FFE0B2,stroke:#E65100
    classDef vis fill:#E1BEE7,stroke:#4A148C

    click RawARFF "https://github.com/alirezaahmadibeni/bankruptcy-prediction/blob/master/1year.arff"
    click RawCSV "https://github.com/alirezaahmadibeni/bankruptcy-prediction/blob/master/xclara.csv"
    click Preprocess "https://github.com/alirezaahmadibeni/bankruptcy-prediction/blob/master/ann.py"
    click Main "https://github.com/alirezaahmadibeni/bankruptcy-prediction/blob/master/main.py"
    click GA "https://github.com/alirezaahmadibeni/bankruptcy-prediction/tree/master/ga/"
    click GA "https://github.com/alirezaahmadibeni/bankruptcy-prediction/blob/master/ga/ga.py"
    click GA "https://github.com/alirezaahmadibeni/bankruptcy-prediction/blob/master/ga/crossover.py"
    click GWO "https://github.com/alirezaahmadibeni/bankruptcy-prediction/tree/master/gwo/"
    click GWO "https://github.com/alirezaahmadibeni/bankruptcy-prediction/blob/master/gwo/gwo.py"
    click Model "https://github.com/alirezaahmadibeni/bankruptcy-prediction/blob/master/ann.py"
    click Silhouette "https://github.com/alirezaahmadibeni/bankruptcy-prediction/blob/master/plot_kmeans_silhouette_analysis.py"
    click Performance "https://github.com/alirezaahmadibeni/bankruptcy-prediction/blob/master/ann.py"
    click Performance "https://github.com/alirezaahmadibeni/bankruptcy-prediction/blob/master/main.py"
```
