What this lesson is, and is not
"Quantum machine learning" covers very different proposals: quantum algorithms for linear algebra on classical data, quantum models trained on classical data, and learning from data that is itself quantum. This lesson focuses on the second family in its simplest, most studied form: supervised classification with a quantum feature map, either as a variational classifier or as a quantum kernel. You will implement a quantum kernel from scratch, compare it with classical baselines on the same data split, and learn the results that constrain what such models can offer.
Nothing here runs on hardware; kernels are computed exactly from state vectors, which is the most favourable setting a quantum model can get. Even so, the comparison has to be fair.
Encoding data into states
A quantum model starts with an encoding circuit that maps a data point to a state .
| encoding | state | qubits | circuit cost | notes |
|---|---|---|---|---|
| basis | for bit strings | gates | only discrete data; one point per basis state | |
| angle | rotations | product state; kernel computable classically (below) | ||
| amplitude | order gates in general | exponentially compact, but generic preparation is expensive |
Amplitude encoding is the source of many exponential-speed-up claims: numbers in qubits. The catch is in the last column. Preparing an arbitrary amplitude vector needs order gates, which is as much work as reading the data classically, unless one assumes a quantum RAM or special structure. Those assumptions are exactly what dequantization results examine, below.
Angle encoding gives a classical kernel
For angle encoding, each qubit is in , so
The overlap of two product states is a product of numbers that a laptop computes in time. Any model built only on this encoding is therefore classically simulable, whatever the number of qubits. To have any chance of being hard to simulate, an encoding must entangle. Havlíček and coauthors proposed entangling feature maps built from products of rotations interleaved with Hadamards, and ran small instances on superconducting hardware (Havlíček et al. 2019). The exercise uses a two-qubit map in that spirit: twice, apply and then the diagonal phase . We call it the "zz" map; it is modelled on, not identical to, the published construction. Since and , one repetition compiles as follows.
Two ways to build a classifier
Variational classifiers. Apply a trainable circuit after the encoding and measure an observable ; the model is , and its sign is the predicted label. Train with the parameter-shift rule from the VQE in practice lesson. Writing and gives : a linear function of the feature "vector" . Schuld and Killoran made this view explicit: the encoding is a feature map into a Hilbert space, and quantum classifiers are linear models in that space (Schuld and Killoran 2019). Training such circuits inherits the optimisation problems of the previous lessons, barren plateaus included (McClean et al. 2018).
Quantum kernels. Instead of training a circuit, use the inner product of feature vectors,
the fidelity kernel, and hand the Gram matrix to a classical kernel method. Because it is an inner product of feature vectors, is symmetric and positive semidefinite, with . On hardware, one entry is estimated by running on and counting how often the all-zero outcome appears: with shots the estimate is binomial with variance .
Kernel ridge classification
Fit to labels by minimising squared error plus a ridge penalty . Setting the gradient to zero gives the linear system
and the predicted label of a new point is . The classical baseline uses the same machinery with the radial basis function kernel , so that the only difference between the models is the kernel. A second, deliberately weak baseline, nearest centroid, assigns a point to the class whose mean is closer.
Worked example. For and , the angle-encoding kernel is , which the exercise's statevector overlap reproduces. The zz kernel of the same pair is , and the RBF kernel with is .
An honest comparison
The dataset: points uniform in , labelled when , an XOR pattern that no linear classifier on the raw features can learn. Forty training points, 200 test points, one seeded split per seed. For each kernel, is chosen by five-fold cross-validation on the training set only; the RBF width is fixed at and not tuned. Test accuracies from the exercise's reference solution:
| seed | quantum zz kernel | quantum angle kernel | classical RBF kernel | nearest centroid |
|---|---|---|---|---|
| 0 | 0.765 | 0.885 | 0.955 | 0.495 |
| 1 | 0.710 | 0.860 | 0.870 | 0.535 |
| 2 | 0.670 | 0.915 | 0.895 | 0.515 |
| 3 | 0.665 | 0.855 | 0.870 | 0.510 |
| 4 | 0.725 | 0.955 | 0.965 | 0.495 |
| 5 | 0.660 | 0.810 | 0.875 | 0.490 |
| mean | 0.699 | 0.880 | 0.905 | 0.507 |
What this shows, for this dataset and protocol: the classical RBF kernel is best on five of six splits; the angle-encoding kernel, which is a classical kernel in disguise, is close behind; the entangling zz map is clearly worse, because its feature geometry does not match the structure of the labels. Nearest centroid is at chance, because the two XOR classes have almost the same mean.
What it does not show: anything about larger problems, about hardware with shot noise, or about datasets with structure that suits a particular quantum feature map. It also illustrates a trap: had the comparison used only nearest centroid as the baseline, every quantum kernel would have "won", by 15 to 46 percentage points depending on the split. A claim of advantage needs the strongest reasonable classical baseline, the same data split, and hyperparameters chosen without looking at the test set.
The evidence on advantage
Dequantization. Many early QML speed-ups assumed that the quantum algorithm could sample from its input data efficiently. Tang showed that a classical algorithm with comparable sampling access solves the recommendation problem with only polynomial overhead (Tang 2019), and Chia and coauthors extended the approach to a framework covering many low-rank linear-algebra tasks (Chia et al. 2020). For these problems the exponential separation disappears once the classical algorithm gets the same input model.
A rigorous speed-up. Liu, Arunachalam and Temme constructed a classification problem, built from the discrete logarithm, that a quantum kernel method learns efficiently, while no efficient classical learner exists unless the discrete logarithm is classically easy (Liu, Arunachalam and Temme 2021). This is a proof that quantum learning advantages can exist, under a standard cryptographic assumption, for data with a specific hidden structure. It is not evidence about typical real-world datasets.
The power of data. Huang and coauthors showed that classical models that are given training data can, in many cases, predict as well as quantum models, even when the quantum model is hard to simulate, and they proposed a test that compares the geometry of a quantum kernel with classical ones before any advantage is claimed (Huang et al. 2021).
Taken together: an advantage for learning from classical data has been proven for a contrived problem, has not been demonstrated for a practical one, and several earlier claims were removed by better classical algorithms. This is an open research area, not a settled negative.
Exponential concentration
There is also a statistical obstacle. Thanasilp, Wang, Cerezo and Holmes proved that, under conditions including highly expressive encodings, entanglement, global measurements and noise, quantum kernel values concentrate exponentially in the number of qubits around a fixed value, so that exponentially many shots are needed to tell kernel entries apart, and a model trained on estimated kernels becomes insensitive to its input (Thanasilp et al. 2024).
Even the humble angle encoding shows the effect, and here it can be derived exactly. Draw independently and uniformly from . Then with , and the factors are independent. Since , and :
Typical off-diagonal entries are of size , and estimating one to relative precision needs of order shots. A seeded check with 20,000 random pairs:
import numpy as np
rng = np.random.default_rng(0)
for n in (1, 2, 4, 8, 16):
a, b = rng.uniform(0, 2 * np.pi, size=(2, 20000, n))
k = np.prod(np.cos((a - b) / 2) ** 2, axis=1)
print(n, f"{k.mean():.2e} vs {0.5**n:.2e}", f"{k.var():.2e} vs {(3/8)**n - 0.25**n:.2e}")
The empirical moments match the formulas up to . At the exact mean is , and even 20,000 samples estimate it poorly (the snippet prints for the mean and half the exact variance), because the average is dominated by rare pairs that happen to be close: concentration makes even the statistics of the kernel expensive to resolve. Rescaling the inputs to a narrower range (a bandwidth parameter) is one mitigation; it also makes the model more classical-like, which is part of the point Huang and coauthors make.
Exercise: a quantum kernel against classical baselines
In quantum-kernel-baseline you implement both encodings, the fidelity kernel from state vectors,
the classical closed form, the RBF kernel, kernel ridge regression, cross-validated choice of ,
nearest centroid, the full comparison, and the concentration statistics. The checks test the zz state
against an independent construction with scipy.linalg.expm, the angle kernel against the closed
form, positive semidefiniteness and unit diagonal of every Gram matrix, interpolation at tiny
, nearest centroid on separable and XOR data, and the empirical concentration moments
against the exact ones.
Common mistakes
- A weak baseline. Nearest centroid, a linear model on XOR data, or an untuned classical kernel makes any model look good.
- Tuning on the test set, or tuning only the quantum model.
- Calling a product-state encoding "quantum". Its kernel is a product of cosines.
- Ignoring encoding cost. Amplitude encoding of arbitrary data costs as much as reading it.
- Ignoring shot noise. Exact kernels are a best case; concentrated kernels need exponentially many shots.
- Reading a rigorous but contrived advantage as a general one, or reading dequantization as a proof that quantum learning is useless.
Summary
Encodings trade qubits for circuit cost, and product encodings are classically simulable: the angle-encoding kernel is . Variational classifiers and fidelity kernels are linear models in the space of encoded states, and kernel ridge regression solves . On a small XOR task with hyperparameters chosen on training data, a classical RBF kernel matched or beat both quantum kernels, while a weak baseline would have suggested the opposite. The literature contains a proven learning advantage for a cryptographically structured problem, dequantization of several earlier claims, and theorems showing that expressive kernels concentrate exponentially. Claims of advantage therefore need strong baselines, fair protocols and explicit assumptions. The final lesson asks what it would cost to run the algorithms of this course on fault-tolerant hardware.