Skip to content

Alaatahaelmaria/Cancer-and-loan-using-FastAPI

Repository files navigation

🧠 ML Project: Cancer & Loan Prediction API

🚀 Overview

This project provides a FastAPI-based ML API that serves two predictive models:

  1. 🧬 Cancer Prediction Models

    • Cancer Type Classification
    • Severity Score Prediction
  2. 💰 Loan Status Prediction

All models are trained using Scikit-learn, tracked with MLflow, and deployed through a FastAPI REST API. You can test and interact with the models easily via Swagger UI at /docs.


🏗️ Project Structure

Caner_and_loan/
│
├── app.py                        # Main FastAPI app
├── train.py                      # Script to train models
├── requirements.txt              # Python dependencies
├── Dockerfile                    # Docker configuration
│
├── models/                       # Saved ML models
│   ├── best_cancer_model.pkl
│   ├── best_loan_model.pkl
│   ├── best_severity_model.pkl
│   └── cancer_label_encoder.pkl
│
├── schemas/                      # Pydantic schemas (API validation)
│   ├── cancer_schema.py
│   └── loan_schema.py
│
├── utils/                        # Helper functions
│   └── model_utils.py
│
├── data/
│   ├── cancer_data.csv
│   └── loan_data.csv
│
└── README.md                     # This file

⚙️ Installation (Local)

1️⃣ Create and activate virtual environment

conda create -n mlflow_env python=3.10 -y
conda activate mlflow_env

or using venv:

python -m venv venv
venv\Scripts\activate

2️⃣ Install dependencies

pip install -r requirements.txt

3️⃣ Train the models

python train.py --cancer_csv data/cancer_data.csv --loan_csv data/loan_data.csv

This will save all trained models inside the models/ folder.


4️⃣ Run the FastAPI server

uvicorn app:app --reload

Then open your browser at: 👉 http://127.0.0.1:8000/docs


🐳 Run with Docker

1️⃣ Build the image

docker build -t mlproject .

2️⃣ Run the container

docker run -d -p 8000:8000 mlproject

3️⃣ Test in browser

Visit: 👉 http://localhost:8000/docs


🧩 API Endpoints

Endpoint Method Description
/ GET Check API status
/predict_cancer_type POST Predict type of cancer
/predict_severity POST Predict cancer severity score
/predict_loan POST Predict loan approval status

📦 Example Request (Cancer Type)

POST /predict_cancer_type

{
  "Age": 45,
  "Gender": "Female",
  "Cancer_Stage": "Stage II",
  "Treatment_Cost_USD": 45000,
  "Survival_Years": 6
}

Response

{
  "cancer_type": "Breast Cancer"
}

🧠 Technologies Used

  • FastAPI — for serving ML models as REST APIs
  • scikit-learn — for model training
  • pandas / numpy — for data preprocessing
  • joblib — for model persistence
  • MLflow — for experiment tracking
  • Docker — for containerized deployment

📈 Results

All models achieved >90% accuracy after hyperparameter tuning and feature optimization.


👨‍💻 Author

Alaa Taha El Maria 🤖 AI Developer | Machine Learning Enthusiast | Problem Solver 📎 LinkedIn 🐦 Twitter


About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors