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

File metadata

  • Download URL: swarmauri_measurement_mutualinformation-0.9.3.dev5.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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.dev5.tar.gz
Algorithm Hash digest
SHA256 628fbe6040c9d0d490e9f3fd6edd05dc9eb6382a660ed7dbe3f6ef7db9ecbbf5
MD5 f6a5205f375e5173caf9fed8ef6f93b9
BLAKE2b-256 a58ff854abdb46e476e23717dae48f46048b7097b7b162e6d848da82613de3af

See more details on using hashes here.

File details

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

File metadata

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

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