An end-to-end machine learning project that predicts loan approval status based on applicant information using various classification algorithms.
- Features
- Tech Stack
- Project Structure
- Installation
- Usage
- Deployment
- API Endpoints
- Model Information
- Contributing
- Machine Learning Pipeline: Complete ML pipeline with data ingestion, transformation, and model training
- Multiple Algorithms: Compares Random Forest, Decision Tree, Gradient Boosting, Logistic Regression, AdaBoost, and SVC
- Web Interface: User-friendly Flask web application for predictions
- RESTful API: Health check and prediction endpoints
- Docker Support: Containerized application for easy deployment
- Azure Deployment: CI/CD pipeline configured for Azure Web Apps
- Logging: Comprehensive logging for debugging and monitoring
- Exception Handling: Custom exception handling throughout the application
- Python 3.11+
- Flask - Web framework
- scikit-learn - Machine learning algorithms
- pandas & numpy - Data manipulation
- Gunicorn - WSGI HTTP Server
- Docker - Containerization
- Azure Web Apps - Cloud deployment
ML_Project/
βββ src/
β βββ Components/
β β βββ data_ingestion.py # Data loading and splitting
β β βββ data_transformation.py # Feature engineering
β β βββ model_trainer.py # Model training and evaluation
β βββ Pipeline/
β β βββ predict_pipeline.py # Prediction pipeline
β β βββ training_pipeline.py # Training orchestration
β βββ Exception.py # Custom exception handling
β βββ Logger.py # Logging configuration
β βββ utils.py # Utility functions
βββ templates/
β βββ index.html # Input form
β βββ home.html # Results page
βββ artifacts/ # Trained models and data
βββ logs/ # Application logs
βββ app.py # Flask application
βββ Dockerfile # Docker configuration
βββ requirements.txt # Python dependencies
βββ setup.py # Package setup
- Clone the repository
git clone <your-repo-url>
cd ML_Project- Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Run the application
python app.pyThe application will be available at http://localhost:5000
- Build the Docker image
docker build -t loan-approval-prediction .- Run the container
docker run -p 8000:8000 loan-approval-predictionThe application will be available at http://localhost:8000
- Navigate to
http://localhost:5000/loan_prediction - Fill in the loan application form with:
- Loan ID
- Number of Dependents
- Annual Income
- Loan Amount
- Loan Term (months)
- CIBIL Score
- Asset Values (Residential, Commercial, Luxury, Bank)
- Education Level
- Self-Employment Status
- Click "Predict" to get the loan approval prediction
To retrain the model with new data:
python src/Components/data_ingestion.pyThis will:
- Load the dataset
- Split into train/test sets
- Transform the data
- Train multiple models
- Save the best model to
artifacts/
# Build
docker build -t loan-approval-prediction .
# Run
docker run -d -p 8000:8000 --name loan-app loan-approval-prediction
# Check logs
docker logs loan-app
# Stop
docker stop loan-appThe project includes a GitHub Actions workflow (.github/workflows/main_loanapprovalprediction.yml) for automatic deployment to Azure:
- Push to the
mainbranch - GitHub Actions will automatically build and deploy
- Access your app at:
https://loanapprovalprediction.azurewebsites.net
AWS Elastic Beanstalk:
eb init -p python-3.11 loan-approval-app
eb create loan-approval-env
eb deployGoogle Cloud Run:
gcloud run deploy loan-approval --source . --platform managed --region us-central1Heroku:
heroku create loan-approval-prediction
git push heroku mainGET /healthResponse:
{
"status": "healthy",
"service": "loan-approval-prediction"
}GET /Returns welcome message
GET /loan_predictionReturns the prediction form
POST /loan_prediction
Content-Type: application/x-www-form-urlencoded
loan_id=1234&no_of_dependents=2&income_annum=500000&...Numerical Features:
- loan_id, no_of_dependents, income_annum, loan_amount, loan_term
- cibil_score, residential_assets_value, commercial_assets_value
- luxury_assets_value, bank_asset_value
Categorical Features:
- education (Graduate/Not Graduate)
- self_employed (Yes/No)
- Random Forest Classifier
- Decision Tree Classifier
- Gradient Boosting Classifier
- Logistic Regression
- AdaBoost Classifier
- Support Vector Classifier (SVC)
The best performing model (accuracy > 90%) is automatically selected and saved.
- Numerical: Median imputation + Standard scaling
- Categorical: Most frequent imputation + One-hot encoding + Scaling
- Target: Label encoding (Approved/Rejected)
The model achieves:
- Accuracy: > 90% on test set
- ROC-AUC: Calculated for models supporting probability estimates
Issue: Module not found
pip install -r requirements.txtIssue: Port already in use
# Change port in app.py or use different port
python app.py # Modify the port in the fileIssue: Model files missing
# Retrain the model
python src/Components/data_ingestion.pyThis project is licensed under the MIT License.
Hammad Ali Tahir
- Email: hammadalitahir8@gmail.com
Contributions, issues, and feature requests are welcome!
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
For support, email hammadalitahir8@gmail.com or open an issue in the repository.
Note: Make sure to place your dataset at src/Notebook/data/loan_approval_dataset.csv before training the model.