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.dev21.tar.gz.

File metadata

  • Download URL: swarmauri_measurement_mutualinformation-0.9.3.dev21.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.dev21.tar.gz
Algorithm Hash digest
SHA256 70653cd92b3d5b88350231862f2500a7c33dc9aed143ad7c6672283933e4f3c1
MD5 807b823b3abd373446456c81eb09bb0b
BLAKE2b-256 62fcbf8e53cca8cdf26d2cc6b8f774d2ce586328c0ce0e50ce371f85fd2028c3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_measurement_mutualinformation-0.9.3.dev21-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.dev21-py3-none-any.whl
Algorithm Hash digest
SHA256 dda138c5a39324d223c9888ae58845d02b664d49ff1058ce6af95f214fa527d3
MD5 c966a120beb0aed3af1dafacf5b831b8
BLAKE2b-256 46f67e01883ec2eb0348d4eac23e5fc4ce09a6bf6e3218a561c7dd4184985517

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