Quantum Computing is an emerging field that incorporates quantum mechanics principles into computing. With Quantum Machine Learning (QML), we blend quantum computing and machine learning to create more efficient algorithms.
IBM’s quantum computing framework, Qiskit, allows us to explore QML. A key component to know in QML is Quantum Support Vector Machines (QSVM).
This post addresses QSVM implementation using Qiskit for binary classification problems. For better understanding, familiarity with basic machine learning and quantum computing is beneficial.
Quantum Support Vector Machines use quantum states to represent data, which increases computational speed, providing a unique approach for solving complex machine learning problems.
from qiskit import BasicAer from qiskit.ml.datasets import ad_hoc_data from qiskit.aqua.utils import split_dataset_to_data_and_labels, map_label_to_class_name from qiskit.aqua import QuantumInstance from qiskit.aqua.algorithms import QSVM, SklearnSVM
Here, we import necessary components from Qiskit.
For simplicity, we use ad_hoc_data from Qiskit's built-in datasets.
feature_dim = 2 # dimension of each data point training_dataset_size = 20 testing_dataset_size = 10 random_seed = 10598 sample_Total, training_input, test_input, class_labels = ad_hoc_data( training_size=training_dataset_size, test_size=testing_dataset_size, n=feature_dim, gap=0.3, plot_data=True ) datapoints, class_to_label = split_dataset_to_data_and_labels(test_input)
This loads the data with 20 training samples and 10 testing samples.
After setting up our dataset, we run the QSVM.
seed = 10598 backend = BasicAer.get_backend('qasm_simulator') feature_map = SecondOrderExpansion(feature_dimension=feature_dim, depth=2, entanglement='linear') svm = QSVM(feature_map, training_input, test_input) quantum_instance = QuantumInstance(backend, shots=1024, seed=seed, seed_transpiler=seed) result = svm.run(quantum_instance)
Here, we are using 'qasm_simulator' backend of Qiskit's BasicAer.
Finally, we can examine the results.
print(f'Testing success ratio: {result['testing_accuracy']}')
This rudimentary introduction to QSVM with Qiskit gives an initial idea of how Quantum Machine Learning can boost conventional machine learning algorithms. The power of quantum states representation is best seen with large complex problems, which can exponentially enhance efficiency.