Skip to main content

Quantum Balanced K-Means Clustering module

Project description

TNO Quantum: ML - Clustering - Balanced K-Means

TNO Quantum provides generic software components aimed at facilitating the development of quantum applications.

This package implements a QUBO based Balanced K-Means clustering algorithm. The implementation has been done in accordance with the scikit-learn estimator API, which means that the clustering algorithm can be used as any other scikit-learn clustering algorithm and combined with transforms through Pipelines.

Limitations in (end-)use: the content of this software package may solely be used for applications that comply with international export control laws.

Documentation

Documentation of the tno.quantum.ml.clustering.bkmeans package can be found here.

Install

Easily install the tno.quantum.ml.clustering.bkmeans package using pip:

$ python -m pip install tno.quantum.ml.clustering.bkmeans

Example

The Balanced K-Means clustering can be used as shown in the following example.

  • Note: This example requires tno.quantum.optimization.solvers[dwave] and tno.quantum.ml.datasets which can be installed along the package using:

    $ python -m pip install tno.quantum.ml.clustering.bkmeans[example]
    
import matplotlib.pyplot as plt
import numpy as np

from tno.quantum.ml.clustering.bkmeans import QBKMeans
from tno.quantum.ml.datasets import get_blobs_clustering_dataset

# Generate sample data
n_centers = 4
X, true_labels = get_blobs_clustering_dataset(
    n_samples=20, n_features=2, n_centers=n_centers
)

# Create QBKMeans object and fit
cluster_algo = QBKMeans(
    n_clusters=n_centers,
    solver_config={
        "name": "simulated_annealing_solver",
        "options": {"number_of_reads": 100},
    },
)
pred_labels = cluster_algo.fit_predict(X)

# Plot results
fig, ax = plt.subplots(nrows=1, ncols=1)
unique_labels = np.unique(pred_labels)
colors = plt.cm.Spectral(np.linspace(0, 1, len(unique_labels)))
for k, col in zip(unique_labels, colors):
    class_member_mask = cluster_algo.labels_ == k
    xy = X[class_member_mask]
    x, y = np.split(xy, 2, axis=1)
    ax.plot(x, y, "o", mfc=tuple(col), mec="k", ms=6)

ax.set_title("Quantum BKMeans clustering")
plt.show()

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

tno_quantum_ml_clustering_bkmeans-2.0.3.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file tno_quantum_ml_clustering_bkmeans-2.0.3.tar.gz.

File metadata

File hashes

Hashes for tno_quantum_ml_clustering_bkmeans-2.0.3.tar.gz
Algorithm Hash digest
SHA256 cf3f672c46d1f7e7a7c252f74f1ef97409212d41212f7e25471b1918a938dadc
MD5 4f25e65b27b78692321548551620149e
BLAKE2b-256 7fd6e3259391259c9e6c724bb96f8754d0884796fd203fd5bcafb8b6c6dd5c20

See more details on using hashes here.

File details

Details for the file tno_quantum_ml_clustering_bkmeans-2.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for tno_quantum_ml_clustering_bkmeans-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 80333b75d872642093234aa24725f9e25960b5835c2a510d9a5153bb4f10e7c5
MD5 85141c2aa36d0d9b741ba675b8588137
BLAKE2b-256 cc8d21a568ab9a8c0603cb33efca0aace83f48137e53b7d700da5ac9fab1a007

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