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.0.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.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ml_mixins-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 b86a6d2a169450d01bf439b94bfb7b76c2141057d970f64141e3a852778cf526
MD5 6d0cc29748e5674367ef1a9201b35818
BLAKE2b-256 8af80fa81b489388ba2b002855b9be800f17be326386b1407259f0538a36265e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ml_mixins-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f968eb818ec7ac348e07c16d96761c55cfe1a7a221c182edfc3d10c4224922ee
MD5 1c050b6a1ef5eb599b88f422fd536787
BLAKE2b-256 5877b270505bb4ef0a4b9f98659e1e71d55396af113d58e5f905efeff3bca1d2

See more details on using hashes here.

Provenance

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