Skip to main content

Command Palette

Search for a command to run...

Contributing CatBoost to a Python AutoML Library — My GitHub PR Walkthrough

The GitHub Issue

Updated
4 min readView as Markdown
Contributing CatBoost to a Python AutoML Library — My GitHub PR Walkthrough

Introduction

In this post, I'll walk you through my recent open source contribution — adding CatBoost support to SwiftPredict, a fully local AutoML and experiment tracking library built with Python. I'll cover the exact code changes, challenges I faced, and how I tested it end-to-end.


What is SwiftPredict?

SwiftPredict is an open source AutoML library that collapses the entire machine learning pipeline into a single fit() call. It handles:

  • Null imputation

  • Categorical and text encoding

  • Task detection (classification vs regression)

  • Class imbalance correction (SMOTE)

  • Multi-model training with 5-fold cross-validation

  • Experiment tracking via local MongoDB

from swiftpredict import AutoML

model = AutoML()
results = model.fit(
    project_name="cancer-prediction",
    file_path="cancer.csv",
    target_column="target"
)
print(results)

The Issue

The maintainer opened Issue #7 requesting CatBoost to be added to the model zoo. The existing model zoo included XGBoost and LightGBM but was missing CatBoost — a gradient boosting library known for handling categorical features natively and performing well in competitive ML.


What is a Model Zoo?

A model zoo is a collection of pre-defined ML models that SwiftPredict trains and evaluates automatically. When you call model.fit(), it trains every model in the zoo and picks the best one.

Before my contribution — 5 models:

  • GaussianNB, XGBClassifier, RandomForestClassifier, LGBMClassifier, LogisticRegression

After my contribution — 6 models:

  • GaussianNB, XGBClassifier, RandomForestClassifier, LGBMClassifier, LogisticRegression, CatBoostClassifier

Same for regression — CatBoostRegressor was added alongside LinearRegression, XGBRegressor, LGBMRegressor, and RandomForestRegressor.


The Changes

Only one file was modified: backend/app/services/preprocessing.py

1. Import CatBoost

from catboost import CatBoostClassifier, CatBoostRegressor  # Importing CatBoost models for classification and regression

2. Add to model_zoo()

def model_zoo(task, model=None):
    if task == "classification":
        models = [GaussianNB, XGBClassifier, RandomForestClassifier,
                  LGBMClassifier, LogisticRegression, CatBoostClassifier]  # Added CatBoostClassifier
    else:
        models = [LinearRegression, XGBRegressor, LGBMRegressor,
                  RandomForestRegressor, CatBoostRegressor]  # Added CatBoostRegressor

3. Handle CatBoost in train_model()

CatBoost doesn't support n_jobs like sklearn models, and prints verbose training logs by default. The fix was to handle it separately with verbose=0:

elif k.__name__ == "CatBoostClassifier":
    model = k(verbose=0)  # verbose=0 suppresses CatBoost console output
if k.__name__ == "CatBoostRegressor":
    model = k(verbose=0)  # verbose=0 suppresses CatBoost console output

This is consistent with how LightGBM is handled using verbose=-1.


Testing

I tested the pipeline end-to-end using the breast cancer dataset from scikit-learn:

from swiftpredict import AutoML

model = AutoML()
results = model.fit(
    project_name="cancer-test",
    file_path="cancer.csv",
    target_column="target"
)

metrics = model.evaluate_performance(key="f1")
print(metrics)

Results:

Training the Models: 100%|████████| 6/6 ✅

Best Models: {'f1': 'LGBMClassifier', 'precision': 'LGBMClassifier',
              'accuracy': 'LGBMClassifier', 'overall': ['LGBMClassifier']}

Metrics: {'accuracy': 0.93, 'f1': 0.93, 'roc_auc': 0.925, 'precision': 0.93}

All 6 models trained successfully with no extra console output from CatBoost.


Challenges I Faced

1. Disk space issues Installing CatBoost (101.7 MB) on a nearly full C: drive caused [Errno 28] No space left on device. Fixed by moving the project to D: drive and clearing pip cache.

2. Virtual environment issues Packages were installing to system Python instead of the venv. Fixed by recreating the venv on D: drive.

3. MongoDB connection The library requires MongoDB for experiment tracking. Used MongoDB Atlas (cloud) instead of installing locally.

4. n_jobs error CatBoost doesn't accept n_jobs as a constructor argument unlike sklearn models. Required a separate elif block to initialize it correctly.


Key Takeaways

  • Open source contributions don't have to be massive — adding one well-tested model with proper handling is valuable

  • Always read the maintainer's guidelines before submitting a PR

  • Test your changes end-to-end before opening a PR

  • Add comments to new code as requested by the maintainer


👉 feat: Add CatBoost support to model zoo


Conclusion

My first open source contribution was small but meaningful — expanding SwiftPredict's model zoo from 5 to 6 models by adding CatBoost support. If you're looking to make your first open source contribution, look for issues labeled good first issue or help wanted on GitHub. Start small, test thoroughly, and follow the maintainer's guidelines.

Happy contributing! 🚀

27 views