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.2.tar.gz (19.0 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.2-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ml_mixins-0.2.2.tar.gz
  • Upload date:
  • Size: 19.0 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.2.tar.gz
Algorithm Hash digest
SHA256 2761d8edbeba3958430ec62f24e0592ecfda0e38347065801ece6b3ff0f01953
MD5 ed0ee8e83099514ff5f000f7c0be80af
BLAKE2b-256 31c414c3c2af765bf54f200c5071f034b8a477c36748116cd1d9ced470710056

See more details on using hashes here.

Provenance

The following attestation bundles were made for ml_mixins-0.2.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: ml_mixins-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 12.3 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e5da20a9c0cbe62df798e83b27acbe9247db245269e91870febebc4a84c10084
MD5 b8adadf399a9fca3b4c139a0e8147598
BLAKE2b-256 508892e0f8a1bb1d56d090ff2f79c23812917e1ad4d0f1b83a3185bbada63a3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ml_mixins-0.2.2-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