Curriculum / Quantum Machine Learning / QML Binary Classifier
QML Binary Classifier
Build a complete variational quantum classifier for a 2-class dataset.
QML Binary Classifier
In this challenge, you'll build a complete variational quantum classifier that distinguishes between two data classes using a trainable quantum circuit.
The Task
Classify 2D data points:
- •Class A: points near [0.3, 0.3] -- label 0 (output P(0) close to 1)
- •Class B: points near [1.5, 1.5] -- label 1 (output P(0) close to 0)
The Circuit Architecture
A 2-qubit variational classifier:
- 1.Encoding layer: Ry(x0, 0), Ry(x1, 1): encode the 2D input point
- 2.Entanglement: CNOT(0, 1): create correlations between encoded features
- 3.Variational layer: : the single trainable parameter
- 4.Measurement: Measure qubit 0: is the classifier output
The classifier outputs . For Class A (label 0), we want close to 1. For Class B (label 1), we want close to 0.
Training by Grid Search
For a single trainable parameter , grid search over in 20 steps. For each :
- 1.Classify Class A point: , want high
- 2.Classify Class B point: , want low
- 3.Compute loss:
- 4.Find that minimizes L
The optimal separates the two classes in Bloch sphere geometry.
Understanding the Result
For Class A: , so rotates both qubits slightly from . After CNOT and , qubit 0 measures close to for the right .
For Class B: , so rotates both qubits significantly. The entangled state after CNOT is very different from Class A, and can be tuned to make qubit 0 measure close to .
The circuit can classify these two points because the encoding + entanglement creates geometrically separated states in Hilbert space.
This classifier uses only a single trainable parameter , yet it can perfectly separate Class A from Class B. This is possible because the encoding and entanglement layers map the two data points to very different quantum states. The variational layer only needs to find the rotation angle that best aligns those states with the measurement axis. Real QML classifiers use more parameters for complex datasets, but the same principle applies: encoding creates the separation, variational layers find the alignment.
How this lesson works
A hands-on coding challenge. You write Qiskit-compatible Python in the browser editor, run it instantly via WebAssembly, watch the circuit and Bloch sphere react, and pass automatic output checks. The AI tutor Qubitus gives Socratic hints if you get stuck.
Part of: Quantum Machine Learning
Apply quantum computing to machine learning with variational circuits and optimization.
This lesson is part of Pro
Unlock Quantum Machine Learning and all 10 tracks with Pro: $12.99/month, $79/year, or $97 lifetime. Start with the free track first if you are new.