📊 FeatureClus: Feature Selection for Clustering Models
Welcome to FeatureClus, a Python library designed to simplify feature selection for clustering models. This tool helps you select the most relevant features that enhance clustering performance, ensuring you avoid the "curse of dimensionality" and make your clustering algorithms more efficient and interpretable. 🧠
🔍 How It Works
The feature selection process is driven by evaluating how each feature impacts the clustering results. FeatureClus uses an isolated data shift for each feature to assess its importance. The process follows these steps:
- MinMaxScaler: First, we scale the features using MinMaxScaler to normalize the data.
- PCA (80% variance): Next, we apply Principal Component Analysis (PCA) to reduce dimensionality, retaining 80% of the variance.
- DBSCAN Clustering: After reducing the dimensionality, DBSCAN is used to perform clustering.
- Silhouette Score Calculation: For each feature, we calculate the silhouette score to evaluate the quality of the clusters. The silhouette score represents how similar an object is to its own cluster compared to other clusters.
- Data Shift and Feature Importance: By applying isolated shifts to each feature and recalculating the silhouette score, we measure how the score changes. The absolute difference in the silhouette score after shifting each feature is used to rank the features by importance.
- Gower matrix: In case of dealing with categorical variables, please use gower matrix.
This method ensures that the features are evaluated for their individual contribution to the clustering process, allowing you to focus on the most impactful features.
🚀 Key Features
- 🔍 Feature Ranking: Ranks features based on the absolute change in silhouette score after applying isolated shifts to each feature.
- 📈 Cluster Evaluation Metrics: Calculates the silhouette score to assess the clustering quality and the influence of each feature.
- 💻 Easy-to-Use API: A simple, intuitive API that can be easily integrated into your machine learning pipeline.
📦 Installation
To install the library, run the following command:
pip install featclus
📊 Example
Here is a quick example of how to use FeatureClus with a clustering algorithm (e.g., KMeans):
from featureclus.model import FeatureSelection
from sklearn.datasets import make_blobs
import pandas as pd
# Sample DataFrame
data, labels = make_blobs(n_samples=10000, centers=7, n_features=15, random_state=42)
df = pd.DataFrame(data, columns=[f"Feature_{i}" for i in range(15)])
# Initialize the FeatureSelection
model = FeatureSelection(data=df, shifts=[1, 25, 50, 75, 100], n_jobs=-1, use_gower=False)
# See how the metrics are important
metrics = model.get_metrics()
🛠️ Methods
get_metrics()
Returns metrics that assess how each feature contributes to clustering.
plot_results(n_features)
Selects the top n_features features based on their importance to clustering results.
☕ Support the Project
If you find this inventory optimization tool helpful and would like to support its continued development, consider buying me a coffee. Your support helps maintain and improve this project!
Other Ways to Support
- ⭐ Star this repository
- 🍴 Fork it and contribute
- 📢 Share it with others who might find it useful
- 🐛 Report issues or suggest new features
Your support, in any form, is greatly appreciated! 🙏
Contributions
- Open a issue.
- Create a new branch based for solving this.
- Send the PR to
devto test the inner functionality.
📝 License
This project is licensed under the MIT License. See the LICENSE file for more details.
Happy clustering! 🎉
Metadata
Release files for featclus 0.1.5
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 |
|---|---|---|---|---|
| featclus-0.1.5.tar.gz | 10.0 kB | With provenance | Details for featclus-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| featclus-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for featclus-0.1.5-py3-none-any.whl |
Total release size: 18.4 kB
Release files / featclus-0.1.5.tar.gz
| Download URL | featclus-0.1.5.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
06835afc3212a479bf4726127ccac8bb7a8bc6e2d6476c4cfe7296f941dacbf9
|
|
BLAKE2b-256 checksum How to use checksums |
b4bfd2f4649b2c8d2a63e5699629dcac900794e6726ddcc56906ef0412ca27f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2025.
Transparency logRelease files / featclus-0.1.5-py3-none-any.whl
| Download URL | featclus-0.1.5-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a25fdc8c26950ddb2c9f0c0a6d7407f16251be18d63ab5f1d473d4e2cb17a9f
|
|
BLAKE2b-256 checksum How to use checksums |
bf442f7c66a8c086aa52719c1118561d9c8142a28ff67e6bcdb9d1290f1746e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2025.
Transparency logSecurity for featclus 0.1.5
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for featclus-0.1.5.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2025.
Transparency logA 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.