A production-ready ML service that predicts customer churn from telecom usage data. Built with FastAPI, scikit-learn, and Docker.
/predict– JSON body with one or more customer records → churn probability/upload– Upload a CSV → batch predictions- Auto-generated docs at
/docs - Example dataset in
data/and a trained pipeline saved toapp/models/churn_pipeline.pkl
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
# (Optional) Retrain pipeline
python app/services/train_model.py --data-path data/train.csv --output app/models/churn_pipeline.pkl
uvicorn app.main:app --reload
# Visit http://127.0.0.1:8000/docsdocker build -t churn-api .
docker run -p 8000:8000 churn-apidocker pull ghcr.io/glaucojrcarvalho/customer-churn-saas:latest
docker run -p 8000:8000 ghcr.io/glaucojrcarvalho/customer-churn-saas:latestcurl -X POST http://127.0.0.1:8000/predict -H "Content-Type: application/json" -d '{
"records": [{
"state": "OH",
"account_length": 103,
"area_code": "area_code_408",
"international_plan": "no",
"voice_mail_plan": "yes",
"number_vmail_messages": 29,
"total_day_minutes": 294.7,
"total_day_calls": 95,
"total_day_charge": 50.10,
"total_eve_minutes": 200.1,
"total_eve_calls": 105,
"total_eve_charge": 17.01,
"total_night_minutes": 300.3,
"total_night_calls": 127,
"total_night_charge": 13.51,
"total_intl_minutes": 13.7,
"total_intl_calls": 6,
"total_intl_charge": 3.70,
"number_customer_service_calls": 1
}]
}'curl -X POST "http://127.0.0.1:8000/upload" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "file=@data/sample_upload.csv"- The pipeline uses a
ColumnTransformerto one-hot encode categorical features and scale numeric features, then aLogisticRegressionclassifier. - You can swap in any estimator (e.g.,
RandomForestClassifier) inside the pipeline.