A containerized inference service for CatBoost classification models with support for numerical, categorical, and text features.
This project provides a production-ready inference container for serving CatBoost classification models. It includes:
- REST API endpoints for predictions
- Comprehensive metrics calculation and visualization
- Support for multiple input types (CSV, JSON)
- Health check endpoint
- AWS SageMaker compatibility
- Python 3.12+
- Docker
- AWS CLI (for ECR deployment)
Core dependencies:
catboost==1.2.8
numpy>=1.26.0
pandas>=2.1.0
scikit-learn>=1.3.2
flask
gunicorn
loguru- Install Poetry if you haven't already:
curl -sSL https://install.python-poetry.org | python3 -- Clone the repository:
git clone https://github.com/yourusername/catboost_inference.git
cd catboost_inference- Install dependencies using Poetry:
poetry install
poetry shell # Activates the virtual environment- Clone the repository:
git clone https://github.com/yourusername/catboost_inference.git
cd catboost_inference- Create a virtual environment and install dependencies:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txtFor development, install additional dependencies:
poetry install --with devThis will install development dependencies like:
- pytest
- pytest-cov
- black
- isort
- mypy
- flake8
catboost_inference/
├── src/
│ ├── inference/ # Core inference code
│ │ └── predictor.py # Model serving logic
│ └── utils/
│ └── metrics.py # Metrics calculation
├── tests/ # Test suites
├── Dockerfile # Container definition
└── build_and_push.sh # ECR deployment script
- Run tests:
pytest tests/ -v- Start the Flask development server:
python src/inference/serveBuild and push to Amazon ECR:
./src/build_and_push.sh <account_id> <ecr_repo_name> <region> [tag_name]GET /pingPOST /invocations
Content-Type: text/csv
<csv-data>The service generates:
- ROC curves
- Confusion matrices
- Precision-recall metrics
- Classification thresholds analysis
Generated plots are saved to the configured image directory.
The project includes comprehensive test suites:
- Unit tests for core functionality
- Integration tests for API endpoints
- Metrics calculation validation
- Plot generation verification
Run tests with coverage:
pytest tests/ -v --cov=src- Deploy using SageMaker Python SDK:
from sagemaker.model import Model
model = Model(
image_uri='<ecr-image-uri>',
model_data='s3://<bucket>/<path>/model.tar.gz',
role='<role-arn>'
)
predictor = model.deploy(
instance_type='ml.c5.xlarge',
initial_instance_count=1
)