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
sphericizeto 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.
Metadata
Release files for bh 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bh-0.0.9.tar.gz | 10.2 kB | Without provenance | Details for bh-0.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bh-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for bh-0.0.9-py3-none-any.whl |
Total release size: 20.7 kB
Release files / bh-0.0.9.tar.gz
| Download URL | bh-0.0.9.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1fbd981edc8a3789e7ce0a923768857ff7bb11d162b87ce8a07838f3077e33b7
|
|
BLAKE2b-256 checksum How to use checksums |
a6052dbdcba3dce1a6744ca23454c5c240cf2769faeb710168261b3f1a1c7c44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.13
|
Release files / bh-0.0.9-py3-none-any.whl
| Download URL | bh-0.0.9-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fcfe660ca176ab7781f919eb5c1ded62735f523f604cb521af54dfa383bd8559
|
|
BLAKE2b-256 checksum How to use checksums |
9dac70f327b70b8a243e01a88eddb8aff0a685f715e92b4ac045039b6a614f88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.13
|
Security for bh 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.