Skip to main content

Swarmauri Mutual Information Measurement Community Package.

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_measurement_mutualinformation


Swarmauri Measurement Mutual Information

Mutual-information measurement plugin for Swarmauri pipelines. Computes the average mutual information (in bits) between every feature column and a target column, letting you rank signal strength before training models.

Features

  • Wraps sklearn.feature_selection.mutual_info_classif behind the standard MeasurementBase API.
  • Supports Pandas DataFrame inputs; automatically excludes the target column from the feature set.
  • Returns the average mutual information across all features (in bits) for quick screening.

Prerequisites

  • Python 3.10 or newer.
  • scikit-learn and pandas installed (pulled in as dependencies of this package).
  • Clean, pre-processed categorical data (encode non-numeric columns before calling) since mutual_info_classif expects numerical inputs.

Installation

# pip
pip install swarmauri_measurement_mutualinformation

# poetry
poetry add swarmauri_measurement_mutualinformation

# uv (pyproject-based projects)
uv add swarmauri_measurement_mutualinformation

Quickstart

import pandas as pd
from swarmauri_measurement_mutualinformation import MutualInformationMeasurement

# Example dataset
frame = pd.DataFrame(
    {
        "feature_a": [0, 1, 1, 0, 1, 0],
        "feature_b": [5.1, 5.0, 4.9, 5.2, 5.1, 5.0],
        "target": [0, 1, 1, 0, 1, 0],
    }
)

mi = MutualInformationMeasurement()
avg_mi = mi.calculate(frame, target_column="target")
print(f"Average mutual information: {avg_mi:.4f} bits")

Per-Feature Scores

If you need the individual MI score per feature, compute it directly and inspect the array:

import pandas as pd
from sklearn.feature_selection import mutual_info_classif

frame = pd.DataFrame(
    {
        "feat1": [0, 1, 1, 0, 1, 0],
        "feat2": [5.1, 5.0, 4.9, 5.2, 5.1, 5.0],
        "target": [0, 1, 1, 0, 1, 0],
    }
)

scores = mutual_info_classif(frame[["feat1", "feat2"]], frame["target"])
for column, score in zip(["feat1", "feat2"], scores):
    print(column, score)

Use the per-feature scores to filter low-signal columns before passing the DataFrame back through Swarmauri.

Tips

  • Normalize or discretize continuous features when comparing very different scales; mutual information is sensitive to distribution assumptions.
  • Handle missing values before calling calculate; mutual_info_classif does not accept NaNs.
  • Binary targets work out of the box; for multi-class targets, ensure target_column contains integer encodings.

Want to help?

If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

Built Distribution

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

File details

Details for the file swarmauri_measurement_mutualinformation-0.9.3.dev4.tar.gz.

File metadata

  • Download URL: swarmauri_measurement_mutualinformation-0.9.3.dev4.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_measurement_mutualinformation-0.9.3.dev4.tar.gz
Algorithm Hash digest
SHA256 16f0a28b600d8b027dc9472760f2d0496cd88112d0e15c249b2112251761924b
MD5 9ff0468da2de8bb616fba71f36a8ebe2
BLAKE2b-256 e24e1fbfbd2d134fee399a51d00802014b7e51841d03ecee4ed7cccdb7c2bb2b

See more details on using hashes here.

File details

Details for the file swarmauri_measurement_mutualinformation-0.9.3.dev4-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_measurement_mutualinformation-0.9.3.dev4-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_measurement_mutualinformation-0.9.3.dev4-py3-none-any.whl
Algorithm Hash digest
SHA256 5bbe008923c7085807d710ebf9719fc9be17b7477414f9f1afbf6ddb2b234d23
MD5 acdc5b31e39f3713b0b51e2982c63444
BLAKE2b-256 aa091325dbb769c3913838956095324a2a89f84877b0dc4352e31d19db3d9f2c

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