Python implementations of the k-Representatives and LSH-k-Representatives algorithms for clustering categorical data:
Different from k-Modes algorithm, k-Representatives and LSH-k-Representatives define the "representatives" that keep the frequencies of all categorical values of the clusters.
Installation:
Using pip:
pip install krepresentatives
Import the packages:
import numpy as np
from krepresentatives.kRepresentatives import kRepresentatives
Generate a simple categorical dataset:
X = np.array([[0,0],[0,1],[0,0],[1,1],[2,2],[2,3],[2,3]])
y = np.array([0,0,0,0,1,1,1])
k-Representatives:
kreps = kRepresentatives(X,y,n_init=5,n_clusters=2 ,verbose=3)
kreps.fit_predict()
Built-in evaluattion metrics:
kreps.CalcScore()
Out come:
kRepresentatives Init 0
Iter 0 Cost: 8.00 Move: 0 Num empty: 0 Timelapse: 0.00
Iter 1 Cost: 4.83 Move: 0 Num empty: 0 Timelapse: 0.00
Iter 2 Cost: 4.83 Move: 0 Num empty: 0 Timelapse: 0.00
kRepresentatives Init 1
Iter 0 Cost: 9.48 Move: 0 Num empty: 0 Timelapse: 0.00
Iter 1 Cost: 6.50 Move: 1 Num empty: 0 Timelapse: 0.00
Iter 2 Cost: 5.33 Move: 0 Num empty: 0 Timelapse: 0.00
Iter 3 Cost: 5.33 Move: 0 Num empty: 0 Timelapse: 0.00
kRepresentatives Init 2
Iter 0 Cost: 9.08 Move: 0 Num empty: 0 Timelapse: 0.00
Iter 1 Cost: 7.60 Move: 0 Num empty: 0 Timelapse: 0.00
Iter 2 Cost: 7.60 Move: 0 Num empty: 0 Timelapse: 0.00
kRepresentatives Init 3
Iter 0 Cost: 9.31 Move: 0 Num empty: 0 Timelapse: 0.00
Iter 1 Cost: 6.50 Move: 1 Num empty: 0 Timelapse: 0.00
Iter 2 Cost: 5.33 Move: 0 Num empty: 0 Timelapse: 0.00
Iter 3 Cost: 5.33 Move: 0 Num empty: 0 Timelapse: 0.00
kRepresentatives Init 4
Iter 0 Cost: 9.42 Move: 0 Num empty: 0 Timelapse: 0.00
Iter 1 Cost: 7.60 Move: 0 Num empty: 0 Timelapse: 0.00
Iter 2 Cost: 7.60 Move: 0 Num empty: 0 Timelapse: 0.00
Score: 4.833333333333334 Time: 0.0015569399999999956
Purity: 1.00 NMI: 1.00 ARI: 1.00 Sil: 0.52 Acc: 1.00 Recall: 1.00 Precision: 1.00
Parameters:
X: Categorical dataset
y: Labels of object (for evaluation only)
n_init: Number of initializations
n_clusters: Number of target clusters
max_iter: Maximum iterations
verbose:
random_state:
Outputs:
cluster_representatives: List of final representatives
labels_: Prediction labels
cost_: Final sum of squared distance from objects to their centroids
n_iter_: Number of iterations
epoch_costs_: Average time for an initialization
LSH-k-Representatives: To be updated
References:
[1] San, Ohn Mar, Van-Nam Huynh, and Yoshiteru Nakamori. "An alternative extension of the k-means algorithm for clustering categorical data." International journal of applied mathematics and computer science 14 (2004): 241-247. [2] To be updated
Metadata
Release files for krepresentatives 1.1.2
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 |
|---|---|---|---|---|
| krepresentatives-1.1.2.tar.gz | 7.6 kB | Without provenance | Details for krepresentatives-1.1.2.tar.gz |
Release files / krepresentatives-1.1.2.tar.gz
| Download URL | krepresentatives-1.1.2.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
38e0c22625e19a28eab6fe807cd51e55ebe879507620793ef2a2195e999ed1ea
|
|
BLAKE2b-256 checksum How to use checksums |
c3d3b361129ad65ed004651aa2e639deabe6a37fc6b464705b24863cad892f98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.8
|
Security for krepresentatives 1.1.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.