Geo Loan UK Predictor

๐Ÿ—บ๏ธ Geo-Loan UK Predictor

Last Commit Repo Size License

Faker Flet Folium SciPy Pandas MySQL

A high-performance Python dashboard for visualizing and analyzing loan risk across the United Kingdom. This application uses SciPy for statistical risk modeling, Flet for a modern UI, and MySQL for persistent data storage.


๐Ÿš€ Key Features

Nationwide Risk Mapping: Interactive Heatmaps generated with Folium.

Statistical Analysis: Real-time Z-score and DTI (Debt-to-Income) calculations.

Full-Stack CRUD: Add, Delete, and Update borrowers with a safety-first UI.

Secure Architecture: Environment-based credential management.


๐Ÿงฎ How the Geo-Loan Engine Works

The risk engine uses a Three-Step Statistical Pipeline:

HOW THE SciPy MATH WORKS: * LEVEL THE FIELD: Credit scores (700) and Debt ratios (0.3) are different sizes. We use Z-Scores to turn them into 'distance from average' so we can compare them fairly. * THE SCORE: Risk = (High Debt) - (Good Credit) - (Work Experience). * THE SQUASH: The result could be any number. We use a 'Sigmoid' function to squish that number into a simple 0 to 1 scale (0% to 100% risk). * THE GRADE: Scores are labeled: 'Safe', 'Caution', or 'High Risk'.


๐Ÿ“ธScreenshots

Screenshot of the dashboard interface Screenshot of adding a new loanee screenshot of adding a new loanee screenshot of new applications entered screenshot of the database


Demo Video

Video of the dashboard


๐Ÿ› ๏ธ Installation & Setup

Prerequisites

Python 3.10+

MySQL Server (Running locally or hosted)

Virtual Environment (Recommended)

Database Configuration

Run the following SQL command in your MySQL terminal to prepare the table:

CREATE TABLE loans (
    id INT AUTO_INCREMENT PRIMARY KEY,
    borrower_name VARCHAR(100),
    amount DECIMAL(15,2),           
    outcode VARCHAR(10),
    is_defaulted TINYINT(1),        
    credit_score INT,
    years_employed INT,
    debt_to_income DECIMAL(5,2),   
    risk_score DECIMAL(5,3) DEFAULT NULL,
    risk_grade VARCHAR(20) DEFAULT NULL
);

Environment Secrets

Create a file named .env in the root directory and add your credentials:

DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password_here
DB_NAME=geoloan_db

Install Dependencies

pip install -r requirements.txt

Populating Data

Once your database table is created and your .env is configured, you must populate the system with synthetic UK borrower data Note: To reset your data at any time, run TRUNCATE TABLE loans; in your MySQL terminal before running the seeder again.

python run_seeder.py

"After running the seeder, your console will confirm 'Successfully inserted 500 records'."


๐Ÿ“‚ Project Structure

โ”œโ”€โ”€ main.py                # App entry point & UI Logic
โ”œโ”€โ”€ run_seeder.py          # IMPORTANT: Database Populater  
โ”œโ”€โ”€ .env                   # Private credentials (ignored by Git)
โ”œโ”€โ”€ .gitignore             
โ”œโ”€โ”€ requirements.txt       # Project dependencies
โ”œโ”€โ”€ database/
โ”‚   โ”œโ”€โ”€ connection.py      # Secure MySQL handshake
โ”‚   โ””โ”€โ”€ queries.py         # SQL CRUD operations
โ”œโ”€โ”€ models/
โ”‚   โ””โ”€โ”€ predictor.py       # SciPy Risk Engine
โ””โ”€โ”€ ui/
    โ”œโ”€โ”€ app_layout.py      # Flet UI Components
    โ””โ”€โ”€ map_generator.py   # Folium Map Logic

๐Ÿšฆ How to Run

Ensure your MySQL server is active. Run the boot sequence:

python main.py

Click "Launch Analysis" to process the data and open the interactive map.

๐Ÿงช To run the full test suite

python -m pytest

๐Ÿ“„ To view the coverage report

python -m pytest --cov=models --cov=database --cov-report=html

๐Ÿ› ๏ธ The Core Tech Stack

Usage: Used in your run_seeder.py to create 600+ realistic borrower records instantly so you didn't have to type them in manually.

Usage: This is your Frontend. It handles the window, the buttons, the input forms, and the "Dark Mode" dashboard you see on your screen.

Usage: It takes the coordinates (Latitude/Longitude) and generates that HTML map with the colored dots for your risk zones.

Usage: You used it to calculate Z-Scores. It compares a borrower's debt against the average of the whole group to determine if they are "High Risk" or "Safe."

Usage: It acts as a bridge. It pulls data from MySQL, cleans it up, and passes it to Folium and SciPy in a neat table format (a "DataFrame").

Usage: Your Persistent Storage. It ensures that if you close the app, your 600 borrowers aren't deletedโ€”they are saved safely in a local database.


๐Ÿง  Technical Challenges & Solutions


๐Ÿ›ฃ๏ธ Roadmap Features