Skip to main content

Cyclic Boosting Machines

Build Python codecov PyPI version License: MIT Academic Paper

This is an efficient and Scikit-learn compatible implementation of the machine learning algorithm Cyclic Boosting -- an explainable supervised machine learning algorithm, specifically for predicting count-data, such as sales and demand.

Features

  • Optimized for categorical features
  • Continuous features are discretized using pandas.qcut.
  • Date auto-expansion (weekday + month).
  • Feature importance plots: categorical, continuous and interactions.
  • Metrics to stop training: RMSE, L1, SMAPE.

Usage

The CBM model predicts by multiplying the global mean with each weight estimate for each bin and feature. Thus the weights can be interpreted as % increase or decrease from the global mean. e.g. a weight of 1.2 for the bin Monday of the feature Day-of-Week can be interpreted as a 20% increase of the target.

with

pip install cyclicbm
import cbm
from sklearn.metrics import mean_squared_error

# load data using https://www.kaggle.com/c/demand-forecasting-kernels-only
train = pd.read_csv('data/train.csv', parse_dates=['date'])
test  = pd.read_csv('data/test.csv',  parse_dates=['date']) 

# feature engineering
min_date = train['date'].min()

def featurize(df):
    out = pd.DataFrame({
        # TODO: for prediction such features need separate modelling
        'seasonal' : (df['date'] - min_date).dt.days // 60,
        'store'    : df['store'], 
        'item'     : df['item'], 
        'date'     : df['date'],
        # <name-1> _X_ <name-2> to mark interaction features
        'item_X_month': df['item'].astype(str) + '_' + df['date'].dt.month.astype(str)
    })
    
    return out

x_train_df = featurize(train)
x_test_df  = featurize(test)
y_train = train['sales']

# model training
model = cbm.CBM()
model.fit(x_train_df, y_train)

# test on train error
y_pred_train = model.predict(x_train_df).flatten()
print('RMSE', mean_squared_error(y_pred_train, y_train, squared=False))

# plotting
model.plot_importance(figsize=(20, 20), continuous_features=['seasonal'])

Feature Importance Plot

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

Release files for cyclicbm 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cyclicbm 0.0.9
File Size Uploaded
cyclicbm-0.0.9.tar.gz 12.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cyclicbm 0.0.9
File Interpreter ABI Platform
cyclicbm-0.0.9-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details

Total release size: 107.4 kB

Release files / cyclicbm-0.0.9.tar.gz

Download URL cyclicbm-0.0.9.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
100e528b50d4af9740433ff15773e94fd105bb31824c566acc9fc95e9c270fbe
BLAKE2b-256 checksum
How to use checksums
c7f8287498151c8a49b873f9ebfa8c3ac2bcef212d9c7b2632ae9943773f58f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release files / cyclicbm-0.0.9-cp38-cp38-win_amd64.whl

Download URL cyclicbm-0.0.9-cp38-cp38-win_amd64.whl
Size 94.6 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
914d516dab243d124f42e8631f6a335105038b5c4e5215146a74f780944698f8
BLAKE2b-256 checksum
How to use checksums
6fa1954ec897df567e3f45acba63068f4e67c53dc790ca4abf4d20b0f3590e8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page