A Python package that helps automate the number of cluster for k-means
Project description
automeans
Python Library for automating the scikit-learn K-Means Clustering Algorithm by optimising the selection of number of clusters.
Introduction
Kmeans algorithm is an iterative algorithm that tries to partition the dataset into K pre-defined distinct non-overlapping subgroups (clusters) where each data point belongs to only one group. It tries to make the intra-cluster data points as similar as possible while also keeping the clusters as different (far) as possible. It assigns data points to a cluster such that the sum of the squared distance between the data points and the cluster’s centroid (arithmetic mean of all the data points that belong to that cluster) is at the minimum. The less variation we have within clusters, the more homogeneous (similar) the data points are within the same cluster.
Problem : As the name suggest, Kmeans algorithm depends upon 'K' which often times is not known by the user at the time of fitting the data. Solution : This library helps automate the selection process for the optimal number of cluster on a given data, along with an optimal fitted model.
Features
- All the main features are adopted from Scikit-Learn Kmeans Algorithm
- Getting the optimally fitted kmeans model
- Getting the optimal number of cluster
Installation
pip install automeans
Usage
Importing the model
from automeans.cluster import ameans
There are 3 metrics to choose from ['standard','kneed','silhouette']
- standard
# Initialize the model
AM = ameans(max_clusters = 5, metrics = 'standard')
# Fit on data 'X'
model, cluster = AM.fit(X)
- kneed
# Initialize the model
AM = ameans(max_clusters = 5, metrics = 'kneed')
# Fit on data 'X'
model, cluster = AM.fit(X)
- silhouette
# Initialize the model
AM = ameans(max_clusters = 5, metrics = 'silhouette')
# Fit on data 'X'
model, cluster = AM.fit(X)
Parameters
For initializing the model max_clusters : The number of maximum seeds to choose metrics : {"standard", "kneed", "silhouette"}, default="standard" Metric to choose the best number of cluster All other parameters are same as used in sklearn Kmeans algorithm
Example
import numpy as np
X = np.array([[1, 2], [2, 5], [3, 6], [8, 7], [8, 8], [7, 3]])
from automeans.cluster import ameans
# Initialize the model
AM = ameans(max_clusters = 5, metrics = 'silhouette')
# Fit on data 'X'
model, cluster = AM.fit(X)
# Predict the cluster on data 'X'
predictions = model.predict(X)
Acknowledgement
Licencse
MIT License
Copyright (c) 2020 Anshul Patel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
File details
Details for the file automeans-1.0.0.tar.gz
.
File metadata
- Download URL: automeans-1.0.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 392b152bebc86bde77798f6934eac2e32c7d800428926ee6947093d2ee5c5129 |
|
MD5 | b2cac2d2880a0a2e1579987eaf7d7812 |
|
BLAKE2b-256 | 0efd88189c6d6c9dadef349ca73b28dc66253c52d3e40ee0d97fd72e4edd5352 |
File details
Details for the file automeans-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: automeans-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c5294ef18bb49ecc246fa55226efa4d7b98abb9f4745223e668a59c3fd40446 |
|
MD5 | 3ea5e332f0da4e7ed49ff726350400c6 |
|
BLAKE2b-256 | 4fd085c4bab076ee8c87e8c2c0eadbfdd673bf72e50f4fb28c98de4907d0546b |