This project demonstrates a complete MLOps pipeline for a Credit Risk Classification application. It uses FastAPI for serving predictions, MLflow for experiment tracking and model registry, and Docker for containerization.
inf334-mlops/
├── docker-compose.yml # Defines services (mlflow-server, app-service)
├── mlruns/ # Shared volume for MLflow artifacts (models, metrics)
├── cred_analysis_app/ # Main application source code
│ ├── Dockerfile # Container definition for the app
│ ├── requirements.txt # Python dependencies
│ ├── data/ # Dataset (german_credit_data.csv) and production logs
│ └── src/
│ ├── train.py # Training script (loads data, trains model, logs to MLflow)
│ └── api.py # FastAPI app (loads model from MLflow, serves predictions)
- Docker and Docker Compose installed on your machine.
-
Start the Services Build and start the MLflow server and the application container.
docker compose up --build -d
- MLflow UI: http://localhost:5001
- API Endpoint: http://localhost:8001
-
Train the Model
[!IMPORTANT] You must run the training script inside the container. This ensures the model is registered with the correct internal network paths (
http://mlflow-server:5000) so the API can find it.docker compose run --rm app-service python src/train.py
Wait for the script to finish. You should see "Model logged to MLflow."
-
Restart the Application The API loads the model only on startup. Since a new model was just trained, restart the service to pick it up.
docker compose restart app-service
-
Test the API Send a sample request to the prediction endpoint.
curl -X POST "http://localhost:8001/predict" \ -H "Content-Type: application/json" \ -d '{ "checking_status": "A11", "duration": 6, "credit_history": "A34", "purpose": "A43", "credit_amount": 1169, "savings_status": "A65", "employment": "A75", "installment_commitment": 4, "personal_status": "A93", "other_parties": "A101", "residence_since": 4, "property_magnitude": "A121", "age": 67, "other_payment_plans": "A143", "housing": "A152", "existing_credits": 2, "job": "A173", "num_dependents": 1, "own_telephone": "A192", "foreign_worker": "A201" }'
Expected Output:
{"risk_prediction": 1, "class": "Good Risk"}
If you wish to run locally (without Docker) using uv:
cd cred_analysis_appuv venvandsource .venv/bin/activateuv pip install -r requirements.txtexport MLFLOW_TRACKING_URI="sqlite:///mlflow.db"python src/train.pyuvicorn src.api:app --host 0.0.0.0 --port 8000 --reload
Siga estes passos exatos para rodar o cenário de teste de Data Drift.
-
Subir os containers
docker compose up --build -d
-
Treinar o modelo Garanta que o modelo está registado no MLflow.
docker compose exec app-service python src/train.py -
Reiniciar API Para carregar o modelo recém treinado.
docker compose restart app-service
-
Rodar simulação de tráfego localmente Use o
uvpara criar um ambiente virtual e instalar as dependências necessárias (pandas,requests).uv venv .venv_traffic source .venv_traffic/bin/activate uv pip install pandas requests python simulate_traffic.py -
Gerar relatório de drift Executa o script de monitoramento dentro do container (onde os logs estão salvos).
docker compose exec app-service python src/monitoring.py -
Visualizar o relatório Abra o HTML gerado no seu navegador (Mac/Linux).
open cred_analysis_app/data/drift_report.html