Skip to main content

Adaptation of X means algorithm for circular data

Project description

circular_clustering

Adaptation of X means algorithm for circular data

install the package using

pip install circular-clustering

X means algorithm with quantiles

The class CircularXMeansQuantiles contains the X means algorithm for circular data. The use is similar to the clustering algorithms in scipy.

To import it use:

from circular_clustering.circular_x_means_quantiles import CircularXMeansQuantiles

To invoke the class use:

circXmeans = CircularXMeansQuantiles(x, kmax=8, confidence=0.99, use_optimal_k_means=True)

Note that kmax= will fix the maximun number of clusters desired.

To fit the algorithm:

circXmeans.fit()

Centroids are available at circXmeans.centroids, while labels are available at circXmeans.labels

Example of use

import numpy as np
import matplotlib.pyplot as plt

from circular_clustering.circular_x_means_quantiles import CircularXMeansQuantiles


x = np.array([ 1.65824313,  1.36928704,  1.78387914,  1.5872978 ,  0.94256866,  1.26848715,
  1.74052966,  2.24549453,  1.95567787,  1.13242718, -1.69442172, -1.1219816 ,
 -1.24971631, -1.8345882 , -1.86868335, -1.35164974, -1.49251909, -1.60791295,
 -1.32335839, -1.91367625,  0.09918781,  0.06024964, -0.07459622, -0.12782416,
  0.17969188,  0.00629938,  0.27335795, -0.28549939,  0.08032582,  0.30140874])


circXmeans = CircularXMeansQuantiles(x, kmax=8, confidence=0.99, use_optimal_k_means=True)
circXmeans.fit()
centroids = circXmeans.centroids

print("number of clusters found: ", len(circXmeans.cluster_points))


plt.figure(figsize=(5,5))
plt.axes().set_aspect('equal', 'datalim')  # before `plt.show()`
plt.scatter(np.cos(x),np.sin(x))

for c in centroids:
    plt.scatter(np.cos(c),np.sin(c), c="r")

for i in range(len(circXmeans.cluster_points)):
    cl = circXmeans.cluster_points[i]
    plt.scatter(np.cos(cl),np.sin(cl), c=np.random.rand(3,))
plt.show()

circXmeans.labels

result

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

circular_clustering-0.0.4.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

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

circular_clustering-0.0.4-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file circular_clustering-0.0.4.tar.gz.

File metadata

  • Download URL: circular_clustering-0.0.4.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for circular_clustering-0.0.4.tar.gz
Algorithm Hash digest
SHA256 ed2b9c37a963174d0e86fb8d1ff0b1cff7d889354a88c8076ec47a4e54eb08d8
MD5 7d4bff967e93ff8e188701cf18d5b16a
BLAKE2b-256 9f6bbb7051327ddf83b464cb3ed85024b93c5b750fda6209ed51c2ba74a21a6f

See more details on using hashes here.

File details

Details for the file circular_clustering-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for circular_clustering-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5799c2221cb2d8fbe5669a7d714cc5803fc18265b94f7d97ea32ad887d426392
MD5 481821f7364590b02787fc4fdf3f6e12
BLAKE2b-256 e1a0f643fd50c7c9e230d9523860ae56fc27ab69e230ae8121c680f23a01c94d

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