Status: Production-Ready | Technology: PyTorch, FastAPI, MLflow | Industry: Financial Services
Project Overview
This is more than a predictive model—it’s a reference implementation for AI Engineering that bridges the gap between data science experimentation and production software. The system evaluates creditworthiness in real-time, providing probability scores and binary predictions for financial decision-making.Watch: Project Demo
Detailed explanation and live demonstration of the Credit Score AI Engine
Watch: Deployment Guide
Step-by-step production deployment with Docker and best practices
Architecture & Components
The project follows a modular architecture with clear separation of concerns:Core Modules
Processing Pipeline (processing/)
Processing Pipeline (processing/)
Location:
processing/preprocessor.pyHandles data cleaning and transformation:- Feature engineering and encoding
- Missing value imputation
- Normalization and scaling
- Train/test splitting
Model Architecture (model/)
Model Architecture (model/)
Location: Key features in
model/model.pyPyTorch-based deep neural network with:- Configurable hidden layers and activation functions
- Batch normalization for training stability
- Dropout regularization to prevent overfitting
- Smart weight initialization (He/Xavier)
model/model.py:58-151:forward(): Standard forward passpredict_probability(): Returns probability scoresbinary_prediction(): Threshold-based classification
Training Pipeline (training/)
Training Pipeline (training/)
Location:
training/training.pyManages the complete training workflow:- YAML-based configuration management
- MLflow experiment tracking
- Model checkpointing
- Metrics logging (loss, accuracy)
config/models-configs/ allow experimentation without code changes:Inference Engine (inference/)
Inference Engine (inference/)
Location:
inference/inference.pyProduction-ready inference module:- Singleton pattern for efficient model loading
- Automatic preprocessing pipeline
- Probability and class predictions
- Error handling and logging
API Server (server/)
API Server (server/)
Location: Enumerated types ensure only valid values are accepted, preventing data quality issues.
server/api.py and server/schemas.pyFastAPI-based REST API with:- Automatic OpenAPI documentation
- Pydantic validation schemas
- CORS middleware for cross-origin requests
- Comprehensive error handling
server/schemas.py:51-96 defines strict input validation:Web Client (examples/client_web/)
Web Client (examples/client_web/)
Interactive web interface for testing and demonstration:
- User-friendly form for input data
- Real-time predictions
- Visualization of results
- Serves as a Backend-for-Frontend (BFF) pattern example
Technical Implementation
Data Schema
The model accepts customer profile data with the following structure:| Field | Type | Description | Constraints |
|---|---|---|---|
| Age | Integer | Customer age in years | Must be > 0 |
| Sex | Enum | Gender | ”male” or “female” |
| Job | Enum | Skill level | ”unskilled and non-resident”, “unskilled and resident”, “skilled”, “highly skilled” |
| Housing | Enum | Housing type | ”own”, “rent”, “free” |
| Saving accounts | Enum | Savings account status | ”NA”, “little”, “moderate”, “quite rich”, “rich” |
| Checking account | Enum | Checking account status | ”NA”, “little”, “moderate”, “rich” |
| Credit amount | Float | Requested credit amount | Must be > 0 |
| Duration | Integer | Credit duration in months | Must be > 0 |
| Purpose | Enum | Credit purpose | ”car”, “furniture/equipment”, “radio/TV”, “domestic appliances”, “repairs”, “education”, “business”, “vacation/others” |
Model Configuration
The neural network architecture is fully configurable viaModelConfig dataclass in model/model.py:19-34:
Supported Activation Functions
The model supports multiple activation functions (seemodel/model.py:37-54):
- ReLU: Standard rectified linear unit
- Leaky ReLU: Prevents dead neurons with small negative slope
- GELU: Gaussian Error Linear Unit (used in transformers)
- Sigmoid: S-shaped curve for probability outputs
- Tanh: Hyperbolic tangent
- Softmax: Multi-class probability distribution
Getting Started
Environment Setup
Install dependencies using UV (modern Python package manager):Or using traditional pip:
Start MLflow Tracking
Launch the MLflow UI to monitor experiments:Access the dashboard at
http://127.0.0.1:5000Train the Model
Execute training with a configuration file:The trained model and metrics are automatically logged to MLflow.
Launch API Server
Start the FastAPI backend:API documentation available at
http://localhost:8000/docsDocker Deployment
For production deployment using containers:- API Server (Port 8000)
- Web Client (Port 3000)
Docker ensures “works on my machine” means “works in production” through consistent, isolated environments.
API Endpoints
POST /credit_score_prediction
Predicts credit risk based on customer data. Request Body Example:prediction: Binary classification (“good” or “bad”)probability: Confidence score for “good” classification (0-1)
Real-World Applications
This credit scoring engine can be deployed across multiple financial verticals:Neobanks & Fintechs
Real-time decision engines for credit card approvals in milliseconds, drastically reducing Customer Acquisition Cost (CAC)
E-commerce BNPL
Native payment gateway integration for instant “Buy Now, Pay Later” financing based on user behavior
Property Technology
Real-time tenant risk evaluation for rental contracts and default insurance
Telecommunications
Dynamic postpaid plan approvals and premium device financing based on payment probability
Microfinance
Alternative scoring models for unbanked populations using demographic and non-traditional transactional data
Insurance Technology
Dynamic premium adjustment based on financial risk profile correlation
MLOps Best Practices
This project exemplifies production-grade ML engineering:Experiment Tracking
- MLflow Integration: All training runs logged with parameters, metrics, and model artifacts
- Version Control: Models versioned and tagged for production deployment
- Reproducibility: Exact experiment replication using logged configurations
Configuration Management
- YAML-based configs: Hyperparameter tuning without code changes
- Environment isolation: UV lock files ensure deterministic dependencies
- Model checkpointing: Automatic saving of best-performing models
Code Quality
- Type hints: Full type annotations for better IDE support and error detection
- Logging: Comprehensive logging at all application layers
- Error handling: Graceful degradation and informative error messages
- Schema validation: Pydantic ensures data quality at API boundaries
Deployment
- Containerization: Docker images for consistent environments
- Orchestration: Docker Compose for multi-service coordination
- Scalability: Stateless API design allows horizontal scaling
- Monitoring: Structured logs for observability
Technology Stack
| Component | Technology | Purpose |
|---|---|---|
| Deep Learning | PyTorch | Neural network implementation |
| API Framework | FastAPI | High-performance REST API |
| Validation | Pydantic | Runtime data validation |
| Experiment Tracking | MLflow | Model versioning and metrics |
| Package Management | UV | Fast, deterministic dependency resolution |
| Containerization | Docker | Environment isolation |
| Orchestration | Docker Compose | Multi-service deployment |
| Data Versioning | DVC | Dataset version control |
Project Structure
Key Takeaways
Why This Project Matters:This isn’t just a machine learning model—it’s a complete AI Engineering solution demonstrating:
- Production-Ready Architecture: Modular design with clear separation of concerns
- DevOps Integration: CI/CD-friendly with containerization and configuration management
- MLOps Maturity: Experiment tracking, model versioning, and reproducibility
- Enterprise Patterns: API-first design, validation layers, and error handling
- Scalability: Stateless design allows horizontal scaling for high-traffic scenarios
Next Steps
Explore the implementation:- Review the model architecture in
python-projects/credit-score/model/model.py - Examine API schemas in
python-projects/credit-score/server/schemas.py - Study the training pipeline in
python-projects/credit-score/training/training.py - Test the API using the interactive Swagger UI
- Experiment with different model configurations
View Source Code
Access the complete source code repository
