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

File metadata

  • Download URL: swarmauri_measurement_mutualinformation-0.9.3.dev17.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.dev17.tar.gz
Algorithm Hash digest
SHA256 9943ff51a86ed30bb7b7400ed7e1922ed732829fef36153337867a8779f6df44
MD5 90a8eaee3568a24faa66129c1942ab55
BLAKE2b-256 ecbc909417ce9fed7bb0f22dd559dd97ae9474f36fea43d125f48b86cc3805f4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_measurement_mutualinformation-0.9.3.dev17-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.dev17-py3-none-any.whl
Algorithm Hash digest
SHA256 ce466aa605f87181c05c37cf00884abec09d1f924befb650f18457399d919503
MD5 165c31f4fe2d50f8388bbc626cc55583
BLAKE2b-256 b9ab2290921219856c625c00fdf375276eb84bef5ff24d5f3eaa8fb9b1e8415e

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