Skip to main content

Build deployable model ensembles without refactoring your code.

Project description

ensemble

A model ensemble utility optimized for low barrier integration

TL;DR this lets you use one thing to call many things.

Model Ensemble

Examples

Define your model functions and create your ensemble:

>>> from ensemble import Ensemble
>>> def square(x):
...     return x**2
...
>>> def cube(y):
...     return y**3
...
>>> my_ensemble = Ensemble(
...     name='e1',
...     children=[function1, function2],
... )

Multiplex between functions:

>>> my_ensemble(child='square', x=2)
4
>>> my_ensemble(child='cube', y=2)
8

Call all the models in the ensemble:

>>> my_ensemble.all(x=2, y=2)
{'square': 4, 'cube': 8}

You may instead decorate your model functions with @model in order to attach them to an ensemble:

>>> from ensemble import child
>>> @child('e2')
... def func1(x):
...     return x**2
...
>>> @child('e2')
... def func2(x):
...     return x**3
...
>>> e2 = Ensemble('e2')
>>> e2.all(x=3)
{'func1': 9, 'func2': 27}

You may even attach a model to multiple ensembles! (this is one main reason ensemble is useful)

>>> @child('e2', 'e3')
... def func3(x, y):
...     return x**3 + y
...
>>> e2.all(x=2, y=3)
{'func1': 4, 'func2': 8, 'func3': 11}
>>>
>>> e3 = Ensemble('e3')
>>> e3.all(x=2, y=3)
{'func3': 11}

If you forget what models are in your ensemble, just check:

>>> e2
Ensemble(
  name='e2',
  children={
    'func1': <function func1 at 0x1024fa9d8>
    'func2': <function func2 at 0x1024faa60>
    'func3': <function func3 at 0x1024fa950>
  },
  weights=None,
)
>>> e3
Ensemble(
  name='e3',
  children={
    'func3': <function func3 at 0x1024fa950>
  },
  weights=None,
)

In the above example, ensemble e2 contains func1, func2, and func3, while ensemble e3 contains just func3.

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

ensemble-pkg-0.0.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

ensemble_pkg-0.0.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file ensemble-pkg-0.0.1.tar.gz.

File metadata

  • Download URL: ensemble-pkg-0.0.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.4

File hashes

Hashes for ensemble-pkg-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5e2a3de60b6f8cd8b454615c062a58658892d138cb432f73df610086b977a1b3
MD5 d94557c941e9c7bb67a0c52946db4d02
BLAKE2b-256 b8e0a8cf72e9f7172eee27ba7d2209623fb6a37b2253e6cfbeb946318759b755

See more details on using hashes here.

File details

Details for the file ensemble_pkg-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: ensemble_pkg-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.4

File hashes

Hashes for ensemble_pkg-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af42de81e4260284894bf1c6aff3318b9e6549945888a8111f681b512a906492
MD5 196ae8b45d15c0ede700db40b0053827
BLAKE2b-256 7f610463c4a5f4351113809e52da0b74645419d5fc86a85ac0cf6109115b74fd

See more details on using hashes here.

Supported by

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