Skip to main content

Fuzzy Linear Discriminant Analysis

Project description

bh: Fuzzy Linear Discriminant Analysis

bh is a Python library implementing Fuzzy Linear Discriminant Analysis (FLDA), an extension of traditional Linear Discriminant Analysis that handles fuzzy or probabilistic class memberships.

Installation

pip install bh

Features

  • Fuzzy Linear Discriminant Analysis: Extends traditional LDA to work with fuzzy class memberships
  • scikit-learn compatible: Implements scikit-learn's estimator interface
  • Dimensionality reduction: Transform high-dimensional data into a lower-dimensional space while preserving class separability
  • Classification: Predict class probabilities and labels for new data points
  • Data preprocessing: Includes utilities like sphericize to transform data to have spherical covariance

Usage

Basic Example

import numpy as np
from bh import FuzzyLDA

# Create some sample data
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
# Fuzzy class membership: each point can partially belong to multiple classes
y = [
    {'class1': 0.8, 'class2': 0.2},
    {'class1': 0.9, 'class2': 0.1},
    {'class1': 1.0, 'class2': 0.0},
    {'class1': 0.1, 'class2': 0.9},
    {'class1': 0.0, 'class2': 1.0},
    {'class1': 0.2, 'class2': 0.8},
]

# Fit model
flda = FuzzyLDA()
flda.fit(X, y)

# Transform data
X_transformed = flda.transform(X)

# Predict on new data
new_data = np.array([[0.8, 1]])
probabilities = flda.predict_proba(new_data)
predicted_class = flda.predict(new_data)

Using with Hard Labels

FLDA also works with traditional hard labels:

from bh import FuzzyLDA

X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
y = [0, 0, 0, 1, 1, 1]  # Hard labels are automatically converted to fuzzy format

flda = FuzzyLDA()
flda.fit(X, y)

Data Preprocessing

from bh import sphericize

X_spherical = sphericize(X, y)

Theory

Fuzzy Linear Discriminant Analysis extends traditional LDA by allowing samples to partially belong to multiple classes. This is particularly useful in scenarios where:

  • Class membership is inherently probabilistic
  • There is uncertainty in class assignments
  • Data points can naturally belong to multiple categories

The algorithm finds a linear transformation that maximizes the ratio of between-class scatter to within-class scatter, while accounting for fuzzy memberships.

License

[License information goes here]

Citation

If you use this software in your research, please cite it.

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

bh-0.0.7.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

bh-0.0.7-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file bh-0.0.7.tar.gz.

File metadata

  • Download URL: bh-0.0.7.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for bh-0.0.7.tar.gz
Algorithm Hash digest
SHA256 2912eb2066096978ab36ef29448dd4f59bf3eec761c08620c51c7078c95a7f2a
MD5 9a08c6e2cd6a2e6ee03bbff3e370daa4
BLAKE2b-256 57fcbecc4f7ff4259620c19a71cd64d1c89fbbf485dda48980563a98534c27ac

See more details on using hashes here.

File details

Details for the file bh-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: bh-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for bh-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6ce9e3928df1effb3b1cf9226a1e81c52a8dd327ed69af5ec4cc2ab90140a53d
MD5 1611936358b4f40afa6e553b08235e9c
BLAKE2b-256 a0bac7efa1d3af57536f5f26c759b8f1658b8568d6abdd90781652831f4f047f

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