Skip to main content

A collection of useful mixins for machine learning development code.

Project description

ML Mixins

PyPI - Version codecov tests code-quality license PRs contributors

This package contains some useful python mixin classes for use in ML / data science, including a mixin for seeding (SeedableMixin), timing (TimeableMixin), and memory tracking (MemTrackableMixin).

Installation

this package can be installed via pip:

pip install ml-mixins

Usage

You can use these mixins either by (1) Defining your classes to inherit from them, then leveraging their included methods in your derived class, or (2) Adding them post-hoc to an existing class for use in secondary applications such as benchmarking or debugging without overhead in production code. Below, we show how to use each mixin directly first, then we show how to add them to an existing class at the end, as that process will still leverage the same decorator methods and class member variables in the resulting modified classes.

Mixin Documentation

SeedableMixin

from mixins import SeedableMixin

class MyModel(SeedableMixin):
    ...

    @SeedableMixin.WithSeed
    def fit(self, X, y):
        # This function can now be called with a seed kwarg, or it will use a pseudo-random seed which will be
        # saved to a class member variable if a seed is not passed.
...

TimeableMixin

TODO

MemTrackableMixin

TODO

Adding Mixins Post-Hoc

from mixins import TimeableMixin, add_mixin


class MyModel:
    ...

    def fit(self, X, y): ...


# Add the mixin to the class
TimedModel = add_mixin(
    MyModel, TimeableMixin, decorate_methods={"fit": TimeableMixin.TimeAs}
)

# Now, the class `TimedModel` will have the same methods as `MyModel`, but with the added timing
# functionality:

model = TimedModel()
model.fit(X, y)
model._profile_durations()  # will print durations...

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

ml_mixins-0.2.1.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

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

ml_mixins-0.2.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file ml_mixins-0.2.1.tar.gz.

File metadata

  • Download URL: ml_mixins-0.2.1.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ml_mixins-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b8098500a7c9dc9301ac97bc980568cdec415be5662c4f7699048e1684c93f99
MD5 feadbcfe4caa1694eb02c01e1a2f398a
BLAKE2b-256 c1cd9ea121758373e1e07ad658b1693fc02bec5d53a9e40f513f102c0d530144

See more details on using hashes here.

Provenance

The following attestation bundles were made for ml_mixins-0.2.1.tar.gz:

Publisher: python-build.yaml on mmcdermott/ML_mixins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ml_mixins-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ml_mixins-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ml_mixins-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d8f5fb223053099053c97a097e275898d49742eaa494fb890cf519908c63f61
MD5 c5bc15eee8400bed50ad5ceb6ae625d1
BLAKE2b-256 3d2bf5fae4f61dec23039d2257c542ecbf0b76942c7763f65eaef76a4ffe260b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ml_mixins-0.2.1-py3-none-any.whl:

Publisher: python-build.yaml on mmcdermott/ML_mixins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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