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.
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

Demo Video
Python 3.10+
MySQL Server (Running locally or hosted)
Virtual Environment (Recommended)
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
);
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
pip install -r requirements.txt
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'."
โโโ 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
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.
python -m pytest
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
Geospatial Data Integrity: * Challenge: Standardizing messy UK Postcode data for mapping.
Solution: Implemented a Regular Expression (Regex) validation layer to extract "Outcodes," ensuring 100% compatibility with the Folium map engine.
Statistical Modeling: * Challenge: Creating a dynamic risk rating from static borrower data.
Solution: Leveraged SciPy's Z-Score functions to normalize multi-variable inputs (DTI, Credit Score), creating a weighted risk algorithm.
Security & Scalability: * Challenge: Protecting sensitive database credentials in a public repository.
Solution: Architected a Decoupled Configuration using .env files and python-dotenv, keeping secrets out of Version Control (Git).
Full-Stack Syncing: * Challenge: Handling high-volume database inserts without UI lag.
Solution: Built a modular CRUD backend in MySQL and integrated it with an asynchronous Flet frontend for a smooth user experience.
๐ฃ๏ธ Roadmap Features
[ ] User Authentication: Implement a secure Login/Sign-up system with hashed passwords using bcrypt to protect lender data.
[ ] Advanced Filtering: Build a sidebar in Flet to filter the map in real-time by Loan Amount, Risk Grade, or specific UK Outcode regions.
[ ] Predictive Machine Learning: Move beyond static Z-scores to a trained Scikit-Learn model that predicts loan default probability based on historical UK financial trends.