Skip to main content

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 :

  1. Making k-means clusters
  2. Querying clusters by id
  3. Sub-clustering k-means clusters by specifying cluster id
  4. Merging k-means clusters by specifying cluster ids

USAGE -

Import kmeans-sam

import kmeans_sam.kmeans_sam as ks

Making clusters

Steps -

  1. Create a k-means model and perform .fit() operations
  2. Create a kmeans-sam object
  3. 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.8.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kmeans_sam-0.1.8-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file kmeans_sam-0.1.8.tar.gz.

File metadata

  • Download URL: kmeans_sam-0.1.8.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for kmeans_sam-0.1.8.tar.gz
Algorithm Hash digest
SHA256 c09be786730d6d4b2ea106b6b161a649c75231197184fdabcb2367a62e00eba6
MD5 fe8eeca1ddafbe1e0ef968b47f6f5872
BLAKE2b-256 e7dd7d37fcfdb457e80876f8d60fbdeb861435a08d1681ab8364c7c725a1bc60

See more details on using hashes here.

File details

Details for the file kmeans_sam-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: kmeans_sam-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for kmeans_sam-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 1c37779e63e8cf5ece0a79ae73a9be05287a78acbfb3d3349f5d3af03fb113de
MD5 182d11cb0a66acd4a1fbc56229201241
BLAKE2b-256 41851a12a7aeba256337bb9cd6ff45aca66241fcc67f232eae8e048e658e824c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page