A package for creating subclusters of KMeansSam clusters and merging them with great flexibility
Project description
k-means-sam
k-means sub-clustering and merging library for strong control and flexibility over k-means clustering
The operations provided in k-means-sam are :
- Making k-means clusters
- Querying clusters by id
- Sub-clustering k-means clusters by specifying cluster id
- Merging k-means clusters by specifying cluster ids
USAGE -
Import kmeans-sam
import kmeans_sam.kmeans_sam as ks
Making clusters
Steps -
- Create a k-means model and perform .fit() operations
- Create a kmeans-sam object
- kmeans-sam.clusterize(model = kmeans_mode, dataframe = df, predictors = [column_names])
Code:
## Create data for clustering
X, _ = make_blobs(n_samples=10, centers=3, n_features=4)
df = pd.DataFrame(X, columns=['Feat_1', 'Feat_2', 'Feat_3', 'Feat_4'])
## Create KMeans model
kmeans = KMeans(n_clusters=3)
kmeans.fit(df[['Feat_1', 'Feat_2', 'Feat_3', 'Feat_4']])
## Create KMeansSam object
kmeans_sam = ks.KMeansSam()
## Create KMeansSam clusters. parameters : kmeans model, dataframe, list of column names
clusters = kmeans_sam.clusterize(kmeans, df, ['Feat_1', 'Feat_2', 'Feat_3', 'Feat_4'])
print(clusters)
Querying cluster by id
Code:
## Fetched all the clusters with id
clusters = kmeans_sam.get_all_clusters()
print(kmeans_sam.get_cluster(2))
Sub-clustering k-means clusters by specifying cluster id
kmeans = KMeans(n_clusters=2)
kmeans.fit(df[['Feat_1', 'Feat_2', 'Feat_3', 'Feat_4']])
## parameters : kmeans model, cluster_id, list of column names
print(kmeans_sam.subclusterize(kmeans, 0, ['Feat_1', 'Feat_2', 'Feat_3', 'Feat_4']))
Merging clusters by cluster_ids
Code:
print(kmeans_sam.merge_cluster([0, 2]))
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
kmeans_sam-0.1.6.tar.gz
(2.6 kB
view hashes)
Built Distribution
Close
Hashes for kmeans_sam-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d2d62d10521adbe8d05920f735384a8d47edc583b48af99e85d20dc1199f43b |
|
MD5 | 9908a3eecdbd01092828b66ba4a5472a |
|
BLAKE2b-256 | 9c4d0d5babdb9d3b4e9efe5148768953dcdf7701d006495670892f8e15edcf59 |