- Overview
- Project Structure
- Key Components
- Technologies Used
- Setup and Installation
- Running the Project
- API Documentation
- Web Application Features
- Data Processing and Model Training
- Testing
- License
This project implements a comprehensive churn prediction system for bank customers. It consists of a machine learning API for making predictions and a web-based user interface for visualizing analytics and interacting with the prediction model.
churn-ticket/
├── data/
│ ├── interim/
│ │ └── churn.db
│ └── processed/
│ ├── df.parquet
│ ├── Xtestfs.parquet
│ ├── Xtrainfs.parquet
│ ├── y_test.pkl
│ └── y_train.pkl
├── docs/
├── notebooks/
├── src/
│ ├── api/
│ │ ├── Dockerfile
│ │ ├── main.py
│ │ ├── routes.py
│ │ └── services.py
│ ├── app/
│ │ ├── Dockerfile
│ │ ├── main.py
│ │ └── page_topics/
│ ├── models/
│ └── scalers/
├── tests/
├── docker-compose.yml
├── pyproject.toml
└── README.md- Built with FastAPI
- Provides endpoints for churn prediction
- Implements feature engineering and machine learning model
- Developed with Streamlit
- Offers interactive data visualizations and analytics
- Allows users to make individual churn predictions
- Scripts for data processing, feature engineering, and model training
- Utilities for visualization and model evaluation
- Python 3.12
- FastAPI
- Streamlit
- Pandas, NumPy, Scikit-learn
- CatBoost
- Docker and Docker Compose
- Poetry for dependency management
-
Clone the repository:
git clone https://github.com/yourusername/churn-ticket.git cd churn-ticket -
Install dependencies (for local development):
poetry install
-
Set up environment variables:
- Create a
.envfile in the root directory - Add necessary environment variables (e.g.,
APIURL,DATABASEURL)
- Create a
docker-compose up --build# Start the API
poetry run uvicorn src.api.main:app --reload
# Start the Streamlit app
poetry run streamlit run src/app/main.py- API: http://localhost:8000
- Web Interface: http://localhost:8501
- Access the API documentation at http://localhost:8000/docs
/predict:POSTrequest for churn prediction
- Home: Project overview and data dictionary
- Model Explanation: Details on the machine learning model used
- Exploratory Data Analysis: Interactive visualizations of customer data
- Top Clients: Analysis of high-value customers
- Churn Prediction: Interface for making individual predictions
- Ticket Simulation: Tool for simulating customer retention strategies
- About: Information about the project and developer
- Data preprocessing scripts are located in
src/data_processing.py - Model training script is in
src/model_training.py - Feature engineering utilities are in
src/utils_feature_engineering.py
Run tests using pytest:
poetry run pytest- Kubernetes cluster (version 1.19+)
- kubectl CLI tool
- Docker (for building images)
Ensure your kubectl is configured to interact with your Kubernetes cluster:
kubectl cluster-info-
Build and push Docker images (if not using pre-built images):
docker build -t guttofranca/churn-ticket-api:latest -f src/api/Dockerfile . docker build -t guttofranca/churn-ticket-app:latest -f src/app/Dockerfile . docker push guttofranca/churn-ticket-api:latest docker push guttofranca/churn-ticket-app:latest
-
Apply Kubernetes configurations:
kubectl apply -f kubernetes/
-
Verify deployments:
kubectl get deployments kubectl get pods kubectl get services
kubectl get service churn-api-serviceNote the external IP or NodePort for accessing the API.
kubectl get service churn-app-serviceNote the external IP or NodePort for accessing the Streamlit app.
- API:
http://<API-EXTERNAL-IP>:8000 - Streamlit App:
http://<APP-EXTERNAL-IP>:8501
Replace <API-EXTERNAL-IP> and <APP-EXTERNAL-IP> with the actual external IPs provided by your Kubernetes cluster.
-
Check pod logs:
kubectl logs <pod-name>
-
Describe resources for more details:
kubectl describe pod <pod-name> kubectl describe service <service-name>
-
For persistent issues, check Kubernetes events:
kubectl get events --sort-by=.metadata.creationTimestamp
-
Ensure services are of type LoadBalancer or NodePort to be accessible externally:
kubectl get services
For more detailed information on Kubernetes concepts and usage, refer to the official Kubernetes documentation.
Distributed under the MIT License. See LICENSE for more information.