https://github.com/bauxn/kernel-kmeans
Project description
Kernel K-Means
Implementation of a Kernel K-Means clustering framework in Python. Utilizes Cython to generate efficient C code.
https://github.com/bauxn/kernel-kmeans
Installation
Installation via Pip does not allow OpenMP. To use OpenMP, see github installation.
Pip
Ensure pip is updated, then run:
pip install KKMeans
Github
Install via:
git clone https://github.com/bauxn/kernel-kmeans
Then open the project folder and run
pip install .
Enabling OpenMP: There is a clearly marked line in setup.py that contains the compiler arguments. Before installing, these need to be edited so that they contain whichever command your compiler uses to enable OpenMP. There already is a outcommented line which contains the correct arguments (and some additional ones for efficiency) for the msvc compiler.
Basic Usage
from KKMeans import KKMeans
kkm = KKMeans(n_clusters=3, kernel="rbf")
kkm.fit(data)
print(kkm.labels_) # shows label for each datapoint
print(kkm.quality_) # print quality (default is inertia) of clustering
predictions = kkm.predict(data_to_predict) # returns labels of points in data_to_predict
KKMeans also contains the modules kernels (provides functionality to build kernel matrices / calculate kernels), elkan and lloyd which allow to calculate single iterations of the respective algorithms and quality, which contains functionality to calculate the silhouette coefficient. For more elaborate usage consult the thesis on github or the docstrings.
Limitations
As the computations happen C, in extreme cases overflows and other datatype errors may occur. Critical points are:
values | datatype |
---|---|
kernel_matrix | double |
n_clusters | long |
cluster_sizes | long |
labels | long |
- The kernel matrix consists of the results of the kernel function, which usually is applied pairwise on the dataset. So ensuring the results are able to fit in a double is necessary.
- Ensure the number of clusters fits in a long.
- Ensure the number of points fits in a long.
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
Hashes for KKMeans-0.1.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c12fcf1ddba5ba542daa064eb633631d1653d46bf06faa2e0b9db45ffc2515f |
|
MD5 | 9bd3e3ea1af6b8a19b24cd78a948fe52 |
|
BLAKE2b-256 | dbb56d2bc79cc7166c768780e9e80817dd9e7f4e2b809e0d8325d87b9d71110e |