A quantum machine-learning experiment is only as reliable as the classical data pipeline that feeds it. This guide shows how to clean and split a dataset, select and scale features, reduce dimensionality, estimate qubit requirements, choose an encoding approach, and create a reproducible small-scale experiment before committing to a larger circuit or hardware run.
Overview
Quantum machine learning (QML) does not remove the need for conventional data preparation. A quantum circuit still receives a finite number of values, and those values must be converted into a form that the chosen circuit, simulator, or quantum service can process. In practice, preprocessing often determines whether an experiment is interpretable before the quantum model is tested.
The central planning question is not simply “How many rows are in the dataset?” It is: How many usable features must be represented, with what precision, on how many qubits, and under what evaluation budget? A dataset with thousands of rows may be manageable if it has only a few carefully selected features. Conversely, a small dataset can become impractical if every column is encoded directly into a deep circuit.
A useful quantum machine-learning pipeline normally has these stages:
- Define the prediction or classification task and the evaluation metric.
- Audit data types, missing values, duplicates, labels, and possible leakage.
- Split the data before fitting transformations that learn from the data.
- Remove irrelevant or redundant features and establish a classical baseline.
- Scale numeric features and encode categorical values explicitly.
- Reduce the feature count to match the circuit and qubit budget.
- Encode the resulting values into a quantum circuit.
- Compare the QML model with the baseline using the same splits and metric.
The preparation stage should be treated as part of the experiment, not as a one-time cleaning task. Changing the feature set, encoding, split, or scaling method changes the problem presented to the quantum model.
How to estimate
Estimate the pipeline from the circuit backward. Start with the available qubit budget and the encoding method, then determine how many features can be represented in one circuit evaluation.
1. Estimate the direct feature requirement
For a simple angle- or rotation-based encoding, one common planning assumption is approximately one feature per qubit per encoding layer. Under that assumption:
Required qubits ≈ number of encoded features
This is a planning estimate, not a universal circuit rule. Re-uploading features across multiple layers can reuse qubits, while other encodings may represent several values in a larger quantum state. The trade-off is usually circuit depth, data-loading complexity, interpretability, or sensitivity to noise.
2. Estimate the amplitude-encoding requirement
Amplitude encoding can represent a vector of length up to 2n using n qubits, so a rough qubit estimate is:
Required qubits = ceiling(log2(padded feature count))
The feature vector may need to be padded to a compatible length and normalized before it is loaded. The lower qubit count does not automatically make this the better choice: state preparation can add substantial circuit work, and the encoding must be supported by the selected software and execution environment.
3. Estimate the sample and evaluation burden
Keep three quantities separate:
- Rows: the number of training, validation, and test examples.
- Features: the number of values presented to the circuit.
- Executions: the number of circuit evaluations required by training, validation, parameter updates, repeated measurements, and any noise or error-mitigation experiments.
A rough execution plan can be expressed as:
Total circuit evaluations ≈ rows used per iteration × training iterations × parameter evaluations × measurement repetitions
The terms depend on the framework, optimizer, batching strategy, and hardware or simulator configuration. Use this equation to compare experiment designs rather than to predict a vendor bill. For hardware costs or service limits, verify the current terms of the selected platform separately.
Preprocessing decision table
| Dataset characteristic | Preparation step | Planning effect | Classical comparison |
|---|---|---|---|
| Different numeric ranges | Fit a scaler on training data only | Produces values suitable for rotation angles or bounded inputs | Use the same transformed data for a logistic or tree-based baseline |
| Many correlated features | Remove redundant columns or apply dimensionality reduction | Reduces qubit and circuit requirements | Measure baseline performance before and after reduction |
| Categorical columns | Choose a documented encoding and handle unseen categories | Prevents accidental ordinal meaning or changing feature counts | Apply the identical category policy to the baseline |
| Class imbalance | Use a split and metric that expose minority-class performance | Avoids misleading accuracy comparisons | Report a suitable classification metric, not accuracy alone |
| Small sample size | Use a fixed split or documented resampling protocol | Reduces variation between experiments | Keep the baseline evaluation protocol identical |
Inputs and assumptions
Before writing quantum programming code, record the inputs that determine the pipeline. This makes the experiment reproducible when the dataset, framework, or qubit budget changes.
- Task: classification, regression, clustering, or another defined objective.
- Target definition: the label or value to predict, including how ambiguous or missing targets are handled.
- Feature inventory: names, types, units, missingness, cardinality, and whether each field is available at prediction time.
- Split policy: train-validation-test proportions or a time-based split where order matters. Select the policy before tuning.
- Random seed: a recorded seed for sampling, splitting, and any stochastic preprocessing.
- Scaling rule: standardization, min-max scaling, robust scaling, or another method selected for the feature distributions.
- Feature budget: the maximum number of values that the circuit can reasonably accept.
- Encoding rule: basis, angle, amplitude, or another approach, with the expected input range documented.
- Baseline: a classical model trained on the same prepared features and evaluated on the same partitions.
Prevent leakage by fitting learned transformations only on the training partition. This includes imputers, scalers, feature selectors, dimensionality-reduction models, and target-informed selection procedures. Apply the fitted transformation to validation and test data without refitting it. If a feature contains information created after the prediction point, remove it even if it appears statistically useful.
For dimensionality reduction, retain a traceable mapping from original columns to reduced features. A reduced feature is not automatically meaningful simply because it lowers the qubit count. Compare the reduced representation with a simpler feature-selection approach, and preserve the transformation object with the experiment configuration.
Encoding constraints also matter. Rotation-based encodings commonly require a defined numeric range; document whether values are clipped, normalized, or mapped by a formula. Avoid silent clipping because it can make distinct observations indistinguishable. For categorical values, decide whether one-hot, ordinal, binary, or learned representations fit the task and the circuit budget. More columns can improve transparency while increasing qubit requirements.
Worked examples
Example 1: Eight features and an angle-encoding prototype
Suppose a binary classification dataset has 1,200 usable rows and 24 numeric columns. After removing identifiers, post-outcome fields, and highly redundant inputs, the team selects eight features. The first experiment uses angle encoding with one feature assigned to each qubit.
- Encoded features: 8
- Planning qubit requirement: approximately 8
- Split: fixed training, validation, and test partitions
- Scaling: fit on training data, then applied unchanged to the other partitions
- Baseline: a classical classifier trained on the same eight scaled features
The first run should use a small, fixed subset of rows and a deterministic seed. Its purpose is to verify loading, preprocessing, encoding, measurement, and metric calculation. It is not yet evidence that the QML model is better. Once the pipeline works, expand the sample while keeping the transformation and evaluation rules stable.
Example 2: Sixteen features with an amplitude-encoding estimate
Now assume the selected representation has 16 numeric features. If the implementation uses amplitude encoding and the vector length is already compatible with a power of two, the rough estimate is:
ceiling(log2(16)) = 4 qubits
That estimate concerns the state-vector dimension only. The team still needs to account for normalization, state preparation, circuit depth, measurement repetitions, and the framework’s supported data-loading method. A four-qubit estimate should therefore be compared with an eight- or 16-qubit angle-encoding design using the same dataset and baseline, rather than treated as an automatic efficiency win.
Example 3: Feature reduction versus direct encoding
A dataset begins with 40 numeric features. A direct angle-encoding prototype would plan for roughly 40 qubits, which may exceed the intended test environment. The team evaluates two alternatives: select six domain-relevant features, or transform the data into six reduced components. Both alternatives fit an angle-encoding prototype with an approximate six-qubit requirement. The decision should be based on validation performance, stability across splits, interpretability, preprocessing cost, and circuit behavior—not on qubit count alone.
When the circuit becomes difficult to interpret or debug, use a simulator and inspect intermediate classical transformations before changing the quantum model. The guides to quantum data encoding methods, quantum circuit simulators, and debugging quantum circuits provide useful next steps.
When to recalculate
Recalculate the pipeline whenever an input that affects representation, evaluation, or execution changes. At minimum, revisit it when:
- the dataset gains or loses columns, rows, labels, or time periods;
- the target definition or prediction timestamp changes;
- missing-value, category, or outlier handling is modified;
- the feature selector, scaler, or dimensionality-reduction method changes;
- the train-validation-test split or random seed changes;
- the encoding method or number of encoding layers changes;
- the available qubit count, gate connectivity, noise profile, or execution limits change;
- the software framework changes its preprocessing or circuit APIs;
- the classical baseline is replaced or its hyperparameters are retuned.
Use this practical checklist before each new experiment:
- Freeze a versioned dataset snapshot and record its row and feature counts.
- Write down the target, split policy, seed, metric, and leakage controls.
- Fit preprocessing only on the training data.
- Calculate the encoded feature count and approximate qubit requirement.
- Confirm that every transformed value satisfies the encoding contract.
- Run a small reproducible subset through a simulator or controlled test environment.
- Run the classical baseline before interpreting the quantum result.
- Expand rows, features, or hardware access one variable at a time.
- Record circuit depth, measurements, failures, runtime, and result variability.
- Recalculate when any dataset, framework, or hardware input changes.
This workflow keeps quantum machine-learning data preparation measurable. It also makes negative results useful: if a model fails, the team can distinguish a data issue, an encoding constraint, a circuit limitation, and a genuine modeling result instead of treating the entire experiment as a black box.