Automatically find the optimal number of clusters (k) for KMeans using the Elbow Method and visualize the result.
Project description
elbowK
This package provides tools for determining the optimal number of clusters in K-Means clustering using the Elbow Method. It automatically calculates the sum of squared errors (SSE) for different values of k, detects the optimal k, and visualizes the results with an elbow plot.
Installation
Install from requirements.txt
pip install -r requirements.txt
Install in development mode (local)
pip install -e .
Install from PyPI
pip install elbowK
Usage
To use the package, import the main function and pass your scaled data:
import pandas as pd
from sklearn.preprocessing import StandardScaler
from elbowK.elbow import find_best_k
# Example dataset
data = pd.DataFrame({
'Income_$': [15, 16, 17, 18, 19, 20],
'SpendingScore': [39, 81, 6, 77, 40, 76]
})
# Scale the data
scaler = StandardScaler()
X_scaled = scaler.fit_transform(data)
# Find the best k and save the elbow plot
best_k = find_best_k(X_scaled, max_k=10, save_plot=True)
print(f"Optimal k: {best_k}")
# The elbow plot will be saved as 'elbow_plot.png' in your working directory.
Package Structure
elbowK/
__init__.py # Initializes the package
elbow.py # Core functionality for determining optimal clusters
setup.py # Package metadata and setup configuration
requirements.txt # Dependencies required
tests/
elbow_test.py # Unit tests
License
This project is licensed under the MIT License – see the LICENSE file for details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file elbowk-1.0.tar.gz.
File metadata
- Download URL: elbowk-1.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fb40c0026a9c0a39cb80a43307e582bcaedd2c635ed031a0f74b34481c0298b
|
|
| MD5 |
432f9f03287a5baef8bcb32c414d1b83
|
|
| BLAKE2b-256 |
b76d5666d79ddcee8258791cdaf6ce2b7f309a0c2d0c67e52fcc2f3d0829dff3
|
File details
Details for the file elbowk-1.0-py3-none-any.whl.
File metadata
- Download URL: elbowk-1.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d1416b31ce6cd7a666e99cfbecde6fad8eb36a6e0541ef24554aa732e6a3fdc
|
|
| MD5 |
15aed73f6d109847a514992468ef6090
|
|
| BLAKE2b-256 |
596b1ff2d79e78aa67436b60f1e9abc95e7a8d4382006faeb3f7083276dbbcfe
|