Skip to main content

Fast Kingfisher rule mining (top-K non-redundant dependency rules via Fisher's exact test) using parallel Branch and Bound.

Project description

kingfisher-bnb

Fast Kingfisher rule mining — the top-K non-redundant, statistically significant dependency rules of a binary/transactional dataset — implemented as a parallel Best-First Branch & Bound search in Rust with a small Python API.

Kingfisher finds rules A ⇒ B (and negative rules A ⇒ ¬B) ranked by a statistical measure, without a minimum-support threshold. False discovery is controlled by algorithmic design — top-K + a non-redundancy rule (a specific rule must beat all its generalizations) + a raw significance cutoff — not by family-wise/FDR correction, so the Fisher scores it returns are raw, uncorrected p-values.

Install

pip install kingfisher-bnb        # prebuilt wheels (Linux/macOS/Windows)

To build from source you need a Rust toolchain (>= 1.85) and maturin:

maturin develop --release         # builds + installs into the active venv

Python usage

import math
import kingfisher_bnb as kf

# Dense rows -> sparse item lists (and an id<->name mapping)
dense = [[1, 1, 0],
         [1, 0, 1],
         [0, 1, 1]]
sparse, id_to_name, _ = kf.dense_to_sparse(dense, ["Apple", "Banana", "Cherry"])

rules = kf.find_rules_from_data(
    data=sparse,
    k=2,            # max attribute index (n_columns - 1)
    q=10,           # top-K rules to keep
    l_max=3,        # max rule length (antecedent + consequent)
    t_type=3,       # 1=positive, 2=negative, 3=both
    m_threshold=1.0,  # raw cutoff (p<=1 => keep all top-q for Fisher)
    measure_type=1,   # 1/2=Fisher's exact, 3=chi^2, 4=mutual info, 5=leverage
)

for r in rules:
    ant = " AND ".join(id_to_name[i] for i in r.antecedent)
    cons = id_to_name[r.consequent]
    sign = "NOT " if r.is_negative else ""
    p = math.exp(r.measure_value)      # Fisher: measure_value = ln(p)
    print(f"IF {ant} THEN {sign}{cons}  (p={p:.4g})")

Each Rule exposes: antecedent (list[int]), consequent (int), is_negative (bool), measure_value (float — ln(p) for Fisher, a negated statistic otherwise so that smaller is always better), and the contingency counts frequency_x, frequency_xa, frequency_a.

CLI

kingfisher --data data/test_data.txt --cols 4 --t-type 3 --measure-type 1

Data format: one transaction per line, space-separated attribute indices.

Measures

measure_type Measure Returns
1, 2 Fisher's exact test ln(p) (raw p-value)
3 Chi-squared test statistic
4 Mutual information bits
5 Leverage effect size

t_type is a separate axis (rule direction): 1 positive, 2 negative, 3 both.

Attribution

This is an independent Rust implementation of the Kingfisher algorithm from Wilhelmiina Hämäläinen's published work — written from the papers, not ported from the original C source. If you use it in research, please cite:

Hämäläinen, W. Efficient discovery of the top-K optimal dependency rules with Fisher's exact test of significance. ICDM 2010.

License

MIT — see LICENSE.

Project details


Download files

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

Source Distribution

kingfisher_bnb-0.1.0.tar.gz (22.0 kB view details)

Uploaded Source

Built Distributions

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

kingfisher_bnb-0.1.0-cp38-abi3-win_amd64.whl (210.5 kB view details)

Uploaded CPython 3.8+Windows x86-64

kingfisher_bnb-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (361.7 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

kingfisher_bnb-0.1.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (356.8 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

kingfisher_bnb-0.1.0-cp38-abi3-macosx_11_0_arm64.whl (314.2 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file kingfisher_bnb-0.1.0.tar.gz.

File metadata

  • Download URL: kingfisher_bnb-0.1.0.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","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 kingfisher_bnb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9076bded032e5d724a5445d30b1bf67daa7756fe91563b55cf73be8b5d99b663
MD5 cfd3fb58d1679a26f8f91dd3d31f19bb
BLAKE2b-256 afb2c3aec1dd4606ac3656920a6b60967f4fa46cfdf1ebb6835a97f7e7f5a47e

See more details on using hashes here.

File details

Details for the file kingfisher_bnb-0.1.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: kingfisher_bnb-0.1.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 210.5 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","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 kingfisher_bnb-0.1.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 eaccf40aa5d245e70b2290c9aa2ce3a19df6fc5e71d636392c530c0b55d4dd1d
MD5 852f41e5f11444d272c66ab5670149fc
BLAKE2b-256 3b65087672233f1fdd02ebd39428011fde9de0813cacb61ece01d77b932e33f6

See more details on using hashes here.

File details

Details for the file kingfisher_bnb-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: kingfisher_bnb-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 361.7 kB
  • Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","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 kingfisher_bnb-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6041c74811d1b4fb4457675a8f3e6db9598ecfba003afbb4f097f02313ce32e0
MD5 0445e468535282d93985597c14ee99ed
BLAKE2b-256 4762bc184e3917e4a4d95e578d8929a493e2bff190727e2c4cb14dccb804fd77

See more details on using hashes here.

File details

Details for the file kingfisher_bnb-0.1.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

  • Download URL: kingfisher_bnb-0.1.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 356.8 kB
  • Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","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 kingfisher_bnb-0.1.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0ecdb67b50d712b329df1368a0417ec419a4824c575b4e7e4960d30bdba2ad79
MD5 92c00eb332134e9b9101adb8b7c3328a
BLAKE2b-256 7fa94d48dd07256146d803c011035b08b8094c0f7cbbdd61063b644165c4f4de

See more details on using hashes here.

File details

Details for the file kingfisher_bnb-0.1.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: kingfisher_bnb-0.1.0-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 314.2 kB
  • Tags: CPython 3.8+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","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 kingfisher_bnb-0.1.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9053c6757b2804d22c030c3857e802583f0946551f3ab8da88d8bddd8b1c9483
MD5 b66a282a27b2aceef53bcafe720919f3
BLAKE2b-256 7a06e1c25fa0ad270f2f14e3d8b1d34b3a6db95d670a91745964e86f302081f6

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