Skip to content

Developed an end-to-end customer churn prediction ML pipeline using Python, pandas, and scikit-learn. Implemented and trained a logistic regression model, then deployed it as a REST API service using FastAPI and containerized with Docker.

License

Notifications You must be signed in to change notification settings

OpenData4Sciece/GLM-Python-ML-Pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Python GML ML Pipeline

✅ Logistic Regression churn prediction
✅ FastAPI REST endpoint
✅ OpenAI summarisation for human-readable explanations

🔧 How to run

  1. Install requirements:
pip install -r requirements.txt
  1. Run locally:
uvicorn app:app --reload
  • app:app loads the FastAPI app from app.py.
  • --reload enables auto-reload for development (useful for code changes, not for production).
  1. Test with:
curl -X POST http://localhost:8000/predict -H "Content-Type: application/json" -d '{
  "age": 45.0,
  "tenure": 24.0,
  "monthly_charges": 79.85,
  "total_charges": 1800.0,
  "contract_type": "Month-to-month",
  "payment_method": "Electronic check"
}'

🔑 Environment Setup

Set your OpenAI API key:

export OPENAI_API_KEY="your_actual_openai_api_key"

📂 Project Structure

Python_GML_ML_Pipeline/
├── app.py                  # FastAPI application
├── requirements.txt        # Python dependencies
├── logistic_model.pkl     # Trained ML model (placeholder)
├── scaler.pkl            # Feature scaler (placeholder)
├── Dockerfile            # Container configuration
├── .gitignore           # Git ignore rules
└── README.md           # This file

🐳 Run with Docker

  1. Build the Docker image:
docker build -t python-gml-ml-pipeline .
  1. Run the Docker container:
docker run -p 8000:8000 -e OPENAI_API_KEY="your_actual_openai_api_key" python-gml-ml-pipeline
  1. Access the FastAPI app:

🧑‍🎓 Learn More - How does this pipeline run?

Execution Flow:

  1. Load trained model and scaler (using joblib).
  2. API endpoint receives JSON data (new user or input data).
  3. Dataframe creation & scaling for consistency with training.
  4. Model predicts churn probability (or other target).
  5. Returns JSON response with prediction for integration into apps or dashboards.

✅ Run locally:

uvicorn app:app --reload

✅ Run in Docker:

docker build -t python-gml-ml-pipeline .
docker run -p 8000:8000 -e OPENAI_API_KEY="your_actual_openai_api_key" python-gml-ml-pipeline

Key reasons to use FastAPI:

  1. Modern async Python framework
  2. Automatic OpenAPI schema & Swagger docs
  3. Production-grade performance
  4. Can be integrated into microservices/SaaS

✨ Author

Pierre-Henry Soria

Made with ❤️ by Pierre-Henry Soria. A super passionate & enthusiastic Problem-Solver / Senior Software Engineer. Also a true cheese 🧀, ristretto ☕️, and dark chocolate lover! 😋

@phenrysay pH-7 YouTube Video BlueSky

📌 Notes

  • logistic_model.pkl and scaler.pkl are placeholders. Train and export your own models using joblib.dump.
  • This project is a modern, production-ready ML pipeline, showcasing deployment and explainability best practices for 2025 and beyond.

🧠 Final Wise Principle

“AI models become valuable when they’re deployable, explainable, and integrated into real products that create business value.”

About

Developed an end-to-end customer churn prediction ML pipeline using Python, pandas, and scikit-learn. Implemented and trained a logistic regression model, then deployed it as a REST API service using FastAPI and containerized with Docker.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published