Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 39 ยท Applications and Outlook

Quantum Machine Learning: Kernels and Variational Classifiers

Learn quantum machine learning basics: data encoding, quantum kernels and variational classifiers, with NumPy simulations on a circle dataset.

Quantum machine learning (QML) asks whether quantum circuits can learn patterns from data better, faster or with less data than classical models. It is one of the most hyped corners of the field, so it pays to be precise about what is known. There are two broad ideas:

  • Classical data, quantum model. Encode ordinary data into qubits, process it with a parameterized circuit, and read out a prediction. This is what runs on today's devices.
  • Quantum data. Learn properties of states that come from a quantum experiment or simulation, where no classical description exists. Here quantum models have the strongest theoretical case.

This lesson covers the core building blocks: encoding data, quantum kernels, and variational classifiers. All examples run on a state-vector simulator in NumPy.

Step 1: getting data into qubits

A classical number cannot be dropped into a qubit directly; you choose an encoding (a feature map):

Encoding How Qubits for d features
Basis Write a binary number as a basis state (5 becomes the state for bits 101) d * bits
Angle Features become rotation angles, `x -> RY(x) 0>`
Amplitude Normalized vector becomes amplitudes of a state log2(d)
Re-uploading Feed the same data in several times, between trainable gates as few as 1

Amplitude encoding is exponentially compact, but preparing a general state takes about d gates, which can erase any speed-up. This data loading problem is the first thing to check in any QML claim.

Quantum kernels

Many classical models (support vector machines, kernel ridge regression, Gaussian processes) depend on data only through a kernel k(x, y), a similarity score. A quantum kernel uses a feature map x -> |phi(x)> and defines

Text
k(x, y) = | <phi(x) | phi(y)> |^2

On hardware this overlap is estimated by running U(x) followed by U(y)^dagger and measuring the probability of returning to |0...0>. The model, training and prediction are classical, so the quantum computer only supplies the kernel matrix. The hope is that for some data the circuit gives a kernel that is hard to compute classically and also useful for the problem.

The next example builds a 2-qubit feature map with Hadamards, Rz angles, a CZ entangler and a data-dependent rotation, then fits kernel ridge regression on a dataset where points are labeled by being inside a circle, and compares it with a classical RBF kernel.

Python A quantum kernel on a circle dataset

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Both reach high accuracy on this easy problem; the quantum kernel is not better here. That is the honest message of most small QML experiments: they are possible, and the question is whether the structure of some real dataset can ever give an advantage.

Variational quantum classifiers

The second approach trains the circuit itself. A typical variational classifier has three parts: a feature map that loads x, a trainable circuit W(theta), and a measurement whose outcome is the prediction (for example, the probability of reading 1 on one qubit). Training is the VQE-style loop: evaluate a loss on training data, compute gradients (by the parameter-shift rule from the SDK lesson), update.

A single qubit is enough to demonstrate data re-uploading: alternate trainable rotations whose angles depend linearly on the input. Repeating this a few times gives a non-linear decision boundary, even on one qubit.

Python A one-qubit re-uploading classifier

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The loss falls from about 0.28 to under 0.08 and the single qubit classifies most test points correctly. On hardware you would compute the gradients with the parameter-shift rule and add shot noise, which slows training.

What is known and what is hype

  • Trainability. Deep or wide random circuits suffer from barren plateaus (vanishing gradients), so useful QML models need structure.
  • Dequantization. Several celebrated QML speed-ups (for recommendation systems, some linear-algebra tasks) were matched by new classical algorithms that use the same data-access assumptions ("quantum-inspired" algorithms).
  • Data loading and readout. Input encoding and extracting statistics from outputs often cost as much as the learning itself.
  • Where promise remains. Learning from quantum data (physics, chemistry sensors), kernels built on circuits that classical machines cannot simulate, and learning problems with an underlying group structure. Theoretical separations exist for contrived tasks; practical advantage on real-world datasets has not been shown.
  • Related tools. Quantum generative models (QCBM, quantum GANs), quantum Boltzmann machines, quantum neural networks and quantum reservoir computing all follow the same hybrid pattern.

Treat any claim that quantum computers "speed up machine learning" with suspicion until you know: what is the encoding cost, which classical baseline was used, and how large was the data?

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is a quantum kernel?

    It is estimated on a quantum device and fed to a classical kernel method such as an SVM.
  2. 2. Why is amplitude encoding often not a free lunch?

    This is the data loading problem, which can cancel any advantage from the compact encoding.
  3. 3. What does data re-uploading mean?

    Re-uploading gives a single qubit enough non-linearity to classify non-trivial patterns.
  4. 4. Which statement about QML advantage is accurate today?

    Dequantization and trainability issues make claims hard to sustain.

Summary

  • QML combines an encoding, a quantum circuit and a classical training procedure.
  • Quantum kernels let a quantum device compute similarities for a classical model; variational classifiers train the circuit directly.
  • Data loading, barren plateaus and strong classical baselines limit practical advantages.
  • The strongest case for QML is learning from quantum data.

Next: Quantum Cryptography and Key Distribution