Skip to content

Latest commit

 

History

37 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Z-Score: Dynamic Trust-Based Credit Framework

CI/CD Pipeline codecov Python 3.8+ License: MIT Code style: black

A hackathon prototype for PSB's FinTech Cybersecurity Hackathon 2025 - Credit Risk Management Track

Overview

Project Z-Score addresses India's dual crisis of credit exclusion (451M individuals lack formal credit access) and rising microfinance delinquencies (163% YoY surge in defaults). Our solution combines alternative data sources, explainable AI, and gamified financial literacy to create a comprehensive credit infrastructure for the underbanked.

Key Innovation

  • Trust-Based Scoring: Dynamic assessment using alternative data (utility bills, social proof, digital footprints)
  • Explainable AI: SHAP-powered decision transparency for regulatory compliance
  • Gamified Journey: Transform credit building from intimidating process to engaging experience
  • DPDPA Compliant: Built with privacy-by-design and regulatory compliance as core principles

Team Z-Row

Quick Start

Installation

  1. Clone and setup:

    git clone https://github.com/Rizzy1857/Z-Cred.git
    cd Z-Cred
    make setup-dev
  2. Run the application:

    make run          # Main application
    make run-user     # User interface
    make run-admin    # Admin dashboard
  3. Run tests:

    make test         # Run all tests
    make test-cov     # With coverage

For detailed setup instructions, see DEVELOPMENT.md.

Features

Core Functionality

  • Dynamic Trust Scoring: Multi-component assessment (Behavioral, Social, Digital Trust)
  • Obscurity Model: Guided journey from credit-invisible to scorable status
  • ML Pipeline: Logistic Regression baseline + XGBoost ensemble with SHAP explainability
  • Gamification: Z-Credits system with missions, achievements, and Trust Bar visualization

Compliance & Security

  • DPDPA Compliance: Granular consent management, data minimization, withdrawal mechanisms
  • RBI Guidelines: Direct fund flow, cooling-off periods, Key Fact Statement generation
  • Secure Architecture: PBKDF2 password hashing, session management, input validation

Alternative Data Integration

  • F1 - Payment History: BBPS utility payment data for financial discipline assessment
  • F2 - Loan Performance: MFI/NGO loan history from informal/semi-formal sources
  • F3 - Social Proof: Community trust metrics from SHG/NGO endorsements
  • F4 - Digital Footprint: Telecom data, transaction SMS patterns, device stability

Technical Architecture

Stack

  • Frontend: Streamlit with custom CSS for professional UI
  • Backend: Python with SQLite for offline-first architecture
  • ML Pipeline: scikit-learn, XGBoost, SHAP for explainable predictions
  • Security: bcrypt, session management, DPDPA-compliant consent flows
  • Visualization: Plotly, Matplotlib for interactive charts and explanations

Project Structure

zscore/
 app.py                 # Main Streamlit application
 auth.py               # Authentication system
 local_db.py           # Database operations
 model_pipeline.py     # ML models and training
 requirements.txt      # Dependencies
 README.md            # This file
 data/
     applicants.db    # Main SQLite database
     sample_data/     # Demo datasets

Installation & Setup

Prerequisites

  • Python 3.8+ (recommended: Python 3.10+)
  • Git
  • 4GB+ available disk space
  • 8GB+ RAM (recommended for optimal performance)

Quick Start (Recommended)

Use our automated setup script for the fastest deployment:

# Clone the repository
git clone <repository-url>
cd Z-Cred

# Run automated setup and launch
./start.sh

# Alternative: Skip setup if already configured
./start.sh --skip-setup

# Start specific application
./start.sh --app=user    # User interface (port 8502)
./start.sh --app=admin   # Admin interface (port 8503)
./start.sh --app=main    # Main interface (port 8501)

Manual Setup (Advanced Users)

  1. Clone the repository

    git clone <repository-url>
    cd Z-Cred
  2. Create virtual environment

    python3 -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  3. Install dependencies (pinned versions)

    pip install --upgrade pip
    pip install -r requirements.txt
  4. Initialize database and demo data

    python setup_demo_data.py
  5. Cache SHAP explainers (optional, for better performance)

    python -c "
    from model_integration import model_integrator
    from shap_cache import cache_shap_explainers
    model = model_integrator.get_credit_model()
    cache_shap_explainers(model)
    print(' SHAP explainers cached for optimal performance')
    "
  6. Run the application

    # Main application
    streamlit run app.py --server.port 8501
    
    # User-focused interface
    streamlit run app_user.py --server.port 8502
    
    # Admin interface
    streamlit run app_admin.py --server.port 8503
  7. Access the application

    • Main App: http://localhost:8501
    • User App: http://localhost:8502
    • Admin App: http://localhost:8503

Production Deployment

For production deployment, use the optimized commands:

# Build production environment
python -m venv prod_env
source prod_env/bin/activate
pip install -r requirements.txt

# Run with production settings
streamlit run app.py --server.port 8501 --server.headless true \
  --server.enableCORS false --server.enableXsrfProtection true

# Or use the launcher script
python launcher.py --production --port 8501

Development Setup

For development with hot-reload and debugging:

# Install development dependencies
pip install pytest pytest-cov black flake8

# Run tests
python -m pytest test_unified_scoring.py -v
python -m pytest test_*.py

# Code formatting
black *.py

# Performance profiling
python -c "
import cProfile
import app_user
cProfile.run('app_user.main()', 'profile_output.prof')
"

Docker Setup (Optional)

# Build Docker image
docker build -t z-cred .

# Run container
docker run -p 8501:8501 z-cred

# Docker Compose for full stack
docker-compose up -d

Troubleshooting

Common Issues:

  1. Port already in use:

    # Find and kill process using port
    lsof -ti:8501 | xargs kill -9
    # Or use different port
    streamlit run app.py --server.port 8504
  2. Database locked errors:

    # Reset database
    rm data/applicants.db
    python setup_demo_data.py
  3. SHAP explainer errors:

    # Clear SHAP cache
    rm -rf cache/shap/
    python -c "from shap_cache import shap_cache; shap_cache.clear_cache()"
  4. Memory issues:

    # Run with memory optimization
    export STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
    streamlit run app.py --server.maxUploadSize 1

Performance Optimization

For optimal performance:

  1. Pre-cache SHAP explainers: Run the caching command above
  2. Use SSD storage: Ensure database is on SSD for faster I/O
  3. Increase RAM: 8GB+ recommended for large datasets
  4. Browser cache: Enable browser caching for faster subsequent loads

Verified Environments

Tested Configurations:

  • macOS 12+ with Python 3.10+
  • Ubuntu 20.04+ with Python 3.8+
  • Windows 10+ with Python 3.9+
  • Docker on Linux/macOS

Performance Benchmarks:

  • Cold start: <30 seconds
  • Warm start: <5 seconds
  • Trust score calculation: <1 second
  • SHAP explanation: <2 seconds (cached)
  • UI response time: <500ms

Demo Scenarios

Z-Cred showcases three realistic scenarios representing different segments of India's credit-invisible population, each demonstrating unique aspects of alternative credit scoring.

Scenario 1: Rural Entrepreneur (Meera - SHG Leader)

Profile: 32-year-old handicraft artisan from Rajasthan, leading a Self-Help Group Credit Need: ₹25,000 for business equipment expansion Trust Score: 77/100

Key Demo Points:

  • Social Proof: SHG leadership and community endorsements
  • Payment History: Consistent utility bill payments despite seasonal income
  • Alternative Data: Government scheme participation and community ratings
  • AI Explanation: SHAP shows community trust as top positive factor

Login: meera@selfhelp.in / demo123

Scenario 2: Urban Gig Worker (Arjun - Delivery Partner)

Profile: 26-year-old food delivery partner from Bangalore Credit Need: ₹80,000 for electric vehicle purchase Trust Score: 83/100

Key Demo Points:

  • Digital Footprint: High platform ratings (4.7+ on Swiggy/Zomato)
  • Income Diversification: Multiple gig platform earnings
  • Real-time Data: GPS tracking, transaction velocity, customer feedback
  • AI Explanation: Platform consistency drives high trust score

Login: arjun@delivery.in / demo123

Scenario 3: Small Business Owner (Fatima - Tailoring Business)

Profile: 38-year-old tailoring business owner from Kerala with 12 years experience Credit Need: ₹1,50,000 for business expansion and equipment Trust Score: 85/100

Key Demo Points:

  • Business Track Record: 12-year operational history with growth trajectory
  • Customer Loyalty: 89% retention rate, excellent online reviews
  • Financial Discipline: Perfect rent payments, supplier relationship management
  • AI Explanation: Business stability and customer trust drive approval

Login: fatima@tailoring.in / demo123

Demo Flow

  1. User Selection: Choose from three distinct personas
  2. Trust Score Analysis: See breakdown of behavioral, social, and digital components
  3. AI Explanations: SHAP-powered transparency for each decision factor
  4. Credit Journey: Gamified missions and achievements for score improvement
  5. Compliance Demo: DPDPA consent management and data transparency

Quick Access: All demo documentation available at docs/DEMO_SCENARIOS.md

Key Metrics & Performance

Model Performance (Synthetic Data)

  • Logistic Regression: AUC ~0.92, F1-Score ~0.89
  • XGBoost Ensemble: AUC ~0.96, F1-Score ~0.93
  • Response Time: <1s per applicant assessment
  • Explainability: 100% decisions explained via SHAP

Business Impact Potential

  • Target Addressable Market: 451M credit-invisible Indians
  • Partner Ecosystem: MFIs, NGOs, Rural Banks, SHGs
  • Risk Reduction Goal: 15-20% improvement in Portfolio at Risk (PAR)

Regulatory Compliance

DPDPA 2023 Compliance

  • Valid consent (free, specific, informed, unambiguous)
  • Purpose limitation (credit assessment only)
  • Data minimization (collect only necessary data)
  • Data localization (India-based storage)
  • Consent withdrawal mechanisms

RBI Digital Lending Guidelines 2025

  • LSP partnership model with regulated entities
  • Direct fund flow (no intermediary handling)
  • Key Fact Statement generation
  • Mandatory cooling-off period
  • Grievance redressal mechanism

Development Status

Completed Features

  • Authentication system with role management
  • SQLite database with offline-first architecture
  • ML pipeline with Logistic Regression + XGBoost
  • Trust scoring framework (Behavioral, Social, Digital components)
  • Basic gamification (Z-Credits, Trust Bar)
  • DPDPA-compliant consent management
  • Professional Streamlit UI

In Progress

  • SHAP integration for explainable AI
  • Advanced visualizations (Trust Bar animations, SHAP plots)
  • Demo data scenarios refinement

Planned Enhancements

  • PDF credit reports generation
  • Offline/online data synchronization
  • Mobile-optimized interface for field agents
  • Account Aggregator framework integration

Usage Guide

for detailed usage guide check Usage Documentation

For Developers

  1. Model training: python model_pipeline.py
  2. Database reset: python -c "from local_db import reset_database; reset_database()"
  3. Add sample data: python -c "from local_db import add_sample_data; add_sample_data()"

API Documentation

Core Functions

  • calculate_trust_score(applicant_data): Returns Trust Bar components and overall score
  • predict_credit_risk(features): ML prediction with confidence intervals
  • generate_shap_explanation(features, prediction): Explainable AI breakdown
  • log_consent(user_id, consent_type, granted): DPDPA compliance logging

Refer detailed documentaion API Documentation

Contributing

This is a hackathon prototype. For the competition:

  1. Focus on demo-ready scenarios
  2. Prioritize visual polish and stability
  3. Ensure all compliance features work smoothly
  4. Test end-to-end user journeys

Refer detailed documentaion Contribution Documentaion*

License

MIT License

Support

For project-related questions:


Built for PSB's FinTech Cybersecurity Hackathon 2025 - Credit Risk Management Track

Empowering India's underbanked through trust, technology, and transparency.

About

An Alternative credit logic app prototype

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages