Skip to main content

Cyclic Boosting Machines

Project description

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.

Usage

pip install cyclicbm
import cbm
import numpy as np

x_train: np.ndarray = ... # will be cast to uint8, so make sure you featurize before hand
y_train: np.ndarray = ... # will be cast to uint32

model = cbm.CBM()
model.fit(x_train, y_train)

x_test: np.numpy = ...
y_pred = model.predict(x_test)

Explainability

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

model = cbm.CBM()
model.fit(x_train, y_train)

import matplotlib.pyplot as plt

fig, axes = plt.subplots(2, 
                         int(np.ceil(x_train.shape[1] / 2)),
                         figsize=(25, 20),
                         sharex=True)

for feature in np.arange(x_train.shape[1]):
    w = model.weights[feature]
    
    ax = axes[feature % 2, feature // 2]
    (ax.barh(x_train.iloc[:,feature].cat.categories.astype(str),
             np.array(w) - 1, # make sure it looks nice w/ bars go up and down from zero
             )
    )
    
    ax.set_title(x_train.columns[feature])
    ax.xaxis.set_tick_params(which='both', labelbottom=True)
    
fig.tight_layout()

Featurization

Categorical features can be passed as 0-based indices, with a maximum of 255 categories supported at the moment.

Continuous features need to be discretized. pandas.qcut for equal-sized bins or numpy.interp for equal-distant bins yield good results for us.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cyclicbm-0.0.7.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cyclicbm-0.0.7-cp38-cp38-win_amd64.whl (88.2 kB view details)

Uploaded CPython 3.8Windows x86-64

File details

Details for the file cyclicbm-0.0.7.tar.gz.

File metadata

  • Download URL: cyclicbm-0.0.7.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for cyclicbm-0.0.7.tar.gz
Algorithm Hash digest
SHA256 b2e53f53bf9463c65066871a7bbe814c37d7d2640a01343672c53972a94d1ef3
MD5 74bb8b7f0bbfb215302d02483fbdfa23
BLAKE2b-256 7150cbcdfacb7d0a92bbab57baeab13d32a2084a52b57d9adbe358d506bafea3

See more details on using hashes here.

File details

Details for the file cyclicbm-0.0.7-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: cyclicbm-0.0.7-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 88.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for cyclicbm-0.0.7-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 4e3b91a7d451627ada9310dfe50a9dc4e90424c2f4b1eead0cef05da0fd0ac81
MD5 2f1c4ac4cc75ec2d007bcc168450a929
BLAKE2b-256 dcd33355ab72e13a889d2e6e2dd9f619292cc53a1eadeaaa43744f605c8e48cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page