Quantum Support Vector Machines — A new era of AI

Alice Liu
8 min readDec 30, 2019

--

The intersection of Quantum Computing and Machine Learning

If quantum systems are able to produce new patterns that classical systems are unable to produce efficiently, can quantum computers outperform classical ones on machine learning tasks? Many machine learning protocols operate by performing specific matrix operations on vectors within high-dimensional vector spaces, which is also what forms the basis of quantum mechanics.

In addition, there is a concept called quantum speedup, which is the potential for the algorithms used in the software of quantum machine learning to outperform classical algorithms for specific problems, having the capacity to transform and take AI to the next level. With all these connections between these two emerging fields, what can we do to maximize the potential of both? (Answer: quantum machine learning (QML), which we’ll talk about after a debrief of classical ML).

Classical ML and Support Vector Machines

Currently, machine learning is split into three main categories: supervised (super task-driven and is able to predict the next value), unsupervised (mostly data-driven and able to identify clusters), and reinforcement (able to learn from mistakes). We are specifically going to highlight supervised learning, which is where support vector machines fall under.

The process of supervised learning, from inputting the raw data and training the dataset under the direction of the “supervisor,” to the final output.

Supervised learning includes using an algorithm to learn the mapping function, y=f(x) from the input to the output based on previous examples of input-output pairs. The mapping function includes labeled training data which consists of a set of training examples. This process of the algorithm learning from the training dataset can be compared to a teacher supervising. The labeled data are the answers and knowing the correct answers, the algorithm is able to make predictions, which is then corrected by the teacher.

Broken down even further, one common algorithm used in the supervised learning process is a Support Vector Machine (SVM), which given labeled training data, will output an optimal hyperplane able to categorize new examples. In other words, in a two-dimensional space for example, it finds a line dividing the plane into two parts, where one class sits on each side.

An example of a 2D case, the hyperplane clearly separates the green data points from the red data points.

The two-dimensional scenario is very straight-forward and easy, but what if we made it more complex by adding a dimension? Referring to the image above on the left, are you able to draw a line separating the red and blue samples? Unless if you’re some wizardly god from Harry Potter, probably not.

However, by doing various transformations and adding a third axis z, we are able to plot these points in the z-axis, we are now easily able to draw a plane, as shown in the above image on the right. The kernel trick was used to do this, which is the mapping of a non-linear data set into a higher dimensional space where you are able to find a hyperplane able to separate the samples.

The Kernel Trick. The left side is the original scenario, and the right side is the result of the mapping after the kernel trick is applied.

Quantum ML and the Quantum SVM Algorithm

But what if the dimensions the data points are projected in keep on getting higher and higher and the dataset becomes more complex? In this case, it would be very difficult for classical computers to operate through these large computations. Even if the classical computer was capable of computing through this, time is another issue. Depending on the number of examples used, features and regularization parameters, it can take up to weeks to train.

Comparisons and implications of Classical Machine Learning (CML) and Quantum Machine Learning (QML). Source

This is where quantum machine learning comes in, harnessing the power of quantum computing to accelerate the training process with accurate classification even with complex datasets in high dimensions. There are quantum interpretations of the SVM kernel trick, allowing the reducing of calculations for a particular dimension and allowing the splitting of these high-dimensional datasets into more manageable ones.

Quantum Machine Learning is the analysis of classical data and quantum states on a quantum computer. The whole essence of it is being able to compute immense quantities of data more intelligently and quickly, providing the computational advantage of classifying objects too complex for classical computers and more thorough data analysis.

The quantum SVM algorithm takes the classical machine learning algorithm and performs the support vector machine on a quantum circuit in order to be efficiently processed on a quantum computer.

Binary Classification of Breast Cancer Cells (Project)

For my personal project, I conducted two simulations on classifying if cells were benign or malignant based on a breast cancer dataset. I carried out the first simulation based on conventional machine learning and a classical SVM algorithm. I applied the quantum SVM algorithm on the second simulation and compared the two simulations based on how accurate the predictions were and how well each one was able to classify.

The breast cancer dataset can be found here. This dataset contains information based on 31 parameters on a tumor including average radius, mean perimeter and texture, etc.

When preparing the breast cancer dataset, a previous data processing is needed to adapt the data into the models used. The relationship between the variables used and which types of data had the most heavy influence are shown in the image below.

In addition, the actual number of benign and malignant cases in the dataset was displayed before applying the dataset to be imported into the algorithm.

The first simulation utilizing the classical algorithm covered the complete dataset and was not limited to the number of parameters as the quantum version in the second simulation (the qubits used only allowed a limited set of information, hence, a limited number of parameters).

The first step in the process is preparing the dataset:

  1. Importing the necessary python packages
  2. Dividing the dataset into training and testing- 30% for testing
  3. Normalizing and scaling the data, putting all the features on the same scale

The second step is importing the algorithm:

  1. Declare the model and train it with the fit() function
  2. Use the test data to create predictions
  3. Create the confusion matrix to show the accuracy of the predictions (visual way of seeing how many times the model was correct and incorrect)

The image above is the confusion matrix, with 3 inaccurate predictions and 168 accurate predictions.

The classification report states the results, with a 97% precision for predicting benign cells and 100% precision when predicting malignant cells.

In the second simulation, the same dataset was used for the quantum SVM. A speedup of the algorithm was provided with IBM’s QCGPU for faster prototyping.

The first step is preparing the dataset for the quantum circuit and importing it:

  1. Import the necessary packages
  2. Load the dataset through sklearn, a link from the data’s website, etc.
  3. Divide the dataset into a training and a test set to find if the classifier is accurate. The data is divided into 70% training and 30% testing here.
  4. Standardize the dataset’s features to fit a normal distribution
  5. Use Principal Component Analysis (PCA) to reduce the data from 31 dimensions to ’n’ dimensions. This is necessary based on the given number of qubits, but while keeping variation, is still able to find patterns.
  6. Scale the data between -1 and 1 to set the range for the SVM
  7. A sample should now be picked to train the model from

The second step is preparing the algorithm by splitting up the data so the algorithm input can be generated:

  1. Set the dimensionality and number of qubits the circuit will have, as well as the training and testing dataset size
  2. Initialize the feature map in order to build the SVM
  3. Set the necessary parameters, including the depth of the circuit, number of shots, and initializing the pseudo-random number generator

A visual of the data classification is generated and shown below, the malignant cells being the orange data points while the benign cells are the blue data points.

The last step is running the algorithm, the run method doing the training, testing and prediction of the unlabeled data. The ground truth, prediction, prediction class, success ratio and accuracy are then generated.

Results

Based on the results, the quantum SVM is able to simulate similar results to a classical SVM. Quantum Computing today is able to do many tasks in machine learning from conventional computers, and is able to solve problems that classical computers are not able to solve, given its potential.

The quantum algorithm was also able to solve the problem faster in this case, having the ability to solve optimization problems in logarithmic order as opposed to the polynomic way used classically. This implementation is growing ever more efficient with the increase in the number of qubits available, and will be able to classify these large and complex datasets at a lower computational cost than what is currently available with classical computers.

Implications for the Future

Quantum Computing is still a new and emerging field, with Quantum Machine Learning even more recent. The future implications for this field are endless, reaching the realms of security, finance, medicine and so much more.

An example is applying QML in examining all the possible scenarios in drug interaction and be able to present the best possible plan of action and an individual’s success with that drug. Especially through a more rigorous understanding of protein folding, it would lead to more precise treatments and overall better outcomes.

A few areas boosted by QML are:

  • Mapping out molecules and atoms for the creation of new materials
  • Modeling molecular interactions at an atomic level, allowing new pharmaceuticals and medical research
  • Space Exploration and the discovery of planets
  • Mapping out the human mind
  • More enhanced pattern recognition and classification
  • Better understanding of nanoparticles

With the new era of QML and current developments being made, will only enforce more powerful AI applications and contribute to the development of quantum computing itself. The ‘future’ is here, be ready for it!

If you liked this article, add a clap and stay in tuned for more articles coming soon! Reach out to me at aliceliu2004@gmail.com or on LinkedIn

--

--