Q-Means algorithm implementation using Qiskit compatible with Scikit-Learn.
The q-means leverages quantum computing to calculate distances for the centroid assignment part of the k-means unsupervised learning algorithm. It shares the same general steps its classical counterpart has, and is used alongside quantum simulators and quantum devices. This implementation uses Qiskit and is compatible with the scikit-learn library in order to exploit the capabilities for machine learning offered by scikit-learn. You can use the q-means in the same way you would use the k-means, and many options are available for data encoding and job batching.
❗ Job batching is introduced as a way to speed up training time on quantum devices for larger datasets. [2]
The project is publicly available in PyPI and can be installed using the following command:
pip install qmeans
Example code for usage of the qmeans algorithm:
import numpy as np
import pandas as pd
from qmeans.qkmeans import *
backend = AerSimulator()
X = pd.DataFrame(np.array([[1, 2], [1, 4], [1, 0], [10, 2], [10, 4], [10, 0]]))
q_means = QuantumKMeans(backend, n_clusters=2, verbose=True)
q_means.fit(X)
print(q_means.labels_)
Python 3.6+
Q-Means uses Qiskit for quantum computations, Scikit-Learn for data preparation and estimator formatting, and Pandas and Numpy for data manipulation.
[1]: D. Quiroga, P. Date and R. Pooser, "Discriminating Quantum States with Quantum Machine Learning," 2021 IEEE International Conference on Quantum Computing and Engineering (QCE), 2021, pp. 481-482, doi: 10.1109/QCE52317.2021.00088.
[2]: D. Quiroga, P. Date and R. Pooser, "Discriminating Quantum States with Quantum Machine Learning," 2021 International Conference on Rebooting Computing (ICRC), 2021, pp. 56-63, doi: 10.1109/ICRC53822.2021.00018.
[3]: D. Quiroga, J. Botia, "Q-means clustering coherent noise tolerance analysis," International Congress EXPOIngenieria, 2022, pp. 437-443.
This source code is free and open source, released under the Apache License, Version 2.0.