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

File metadata

  • Download URL: swarmauri_measurement_mutualinformation-0.9.3.dev18.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.dev18.tar.gz
Algorithm Hash digest
SHA256 3e49e6367112ef93b88b3a090e8de21b8f531c697b5e23c4259576fcb708ac8d
MD5 02ba911ff0e9ba311a84be5854b2e498
BLAKE2b-256 e35a5406eb055314dd2ec9c5c7b0c4426fe85aa1c3cc58f00fcdb308b28ecb7b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_measurement_mutualinformation-0.9.3.dev18-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.dev18-py3-none-any.whl
Algorithm Hash digest
SHA256 9250257ace4bc84d52d0d8620cb4e887e60a2d81e038a8330912c9cf7f502cc7
MD5 e84c9b12f11718c04fdd46ce7f8b59ae
BLAKE2b-256 98502ba0763937168465e2e499fd8a4c202f86323e897e66d2c6a20ef039c1f5

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