Skip to content

Benchmark Datasets for QML

Classical Datasets Used in QML Research

Table 1. Standard classification datasets for QML benchmarking
Dataset Samples Features Classes Source
Iris 150 4 3 UCI
Wine 178 13 3 UCI
Breast Cancer 569 30 2 UCI
Heart Disease 303 13 2 UCI
MNIST 70,000 784 10 LeCun et al.
Fashion-MNIST 70,000 784 10 Xiao et al.
CIFAR-10 60,000 3072 10 Krizhevsky

Quantum and Molecular Datasets

Table 2. Quantum and chemistry datasets for QML
Dataset Description Size Source
QM9 Molecular properties (134k molecules) 134k Ramakrishnan et al.
QM7 Molecular energies (7k molecules) 7k Rupp et al.
PubChemQC Quantum chemistry data 3M+ Nakata et al.
OC20 Open Catalyst (adsorption) 1.2M Meta AI
QM-sym Molecules with symmetry labels 50k QML group
ZINC Drug-like molecules 250k Irwin et al.
ChEMBL Bioactivity data 2M+ Mendez et al.

Loading Datasets in Python

# -- Classical datasets ----------------------------------------
from sklearn.datasets import (load_iris, load_wine, load_breast_cancer,
                               fetch_openml, make_classification)
import numpy as np

# Iris (4 features, 3 classes)
iris = load_iris()
X_iris, y_iris = iris.data, iris.target

# Breast cancer (30 features, 2 classes)
bc = load_breast_cancer()
X_bc, y_bc = bc.data, bc.target

# MNIST (via scikit-learn)
mnist = fetch_openml('mnist_784', version=1, as_frame=False)
X_mnist = mnist.data / 255.0  # normalize to [0,1]
y_mnist = mnist.target.astype(int)

# -- MNIST subset for QML -------------------------------------
from sklearn.decomposition import PCA
from sklearn.preprocessing import MinMaxScaler

# Reduce MNIST to 4 dimensions for 4-qubit QML
pca = PCA(n_components=4)
X_pca = pca.fit_transform(X_mnist[:1000])
X_qml = MinMaxScaler(feature_range=(0, np.pi)).fit_transform(X_pca)

# Binary: digits 0 vs 1
mask = y_mnist[:1000] <= 1
X_01, y_01 = X_qml[mask], y_mnist[:1000][mask]
print(f"Binary MNIST (0 vs 1): {X_01.shape}, classes: {np.unique(y_01)}")

# -- Molecular datasets ----------------------------------------
# QM9 via RDKit/DeepChem
try:
    import deepchem as dc
    tasks, datasets, transformers = dc.molnet.load_qm9()
    train, val, test = datasets
    print(f"QM9 train size: {len(train)}")
except ImportError:
    print("DeepChem not installed. Install with: pip install deepchem")

# Morgan fingerprints for molecular ML
try:
    from rdkit import Chem
    from rdkit.Chem import AllChem
    import numpy as np

    smiles_list = ['CCO', 'CC(=O)O', 'c1ccccc1', 'C1CCCCC1']
    fps = []
    for smi in smiles_list:
        mol = Chem.MolFromSmiles(smi)
        fp = AllChem.GetMorganFingerprintAsBitVect(mol, radius=2, nBits=1024)
        fps.append(np.array(fp))
    fps = np.array(fps)
    print(f"Fingerprint shape: {fps.shape}")
except ImportError:
    print("RDKit not installed. Install with: pip install rdkit")

# -- Time series for QLSTM ------------------------------------
def generate_sine_dataset(n_sequences=200, seq_len=20):
    """Generate binary frequency classification dataset."""
    X = np.zeros((n_sequences, seq_len, 1))
    y = np.zeros(n_sequences, dtype=int)
    for i in range(n_sequences):
        freq = np.random.uniform(0.1, 1.0)
        t = np.linspace(0, 1, seq_len)
        X[i, :, 0] = np.sin(2 * np.pi * freq * t)
        y[i] = int(freq > 0.5)  # 1 if high frequency
    return X, y

X_seq, y_seq = generate_sine_dataset()
print(f"Sine sequence dataset: X={X_seq.shape}, y={y_seq.shape}")
print(f"Class balance: {y_seq.mean():.2f} (high freq)")

Dataset Preprocessing for QML

from sklearn.preprocessing import MinMaxScaler, StandardScaler
from sklearn.decomposition import PCA
from sklearn.model_selection import train_test_split
import numpy as np

def prepare_for_qml(X, y, n_features=4, test_size=0.2,
                     encoding='angle', random_state=42):
    """
    Standard QML preprocessing pipeline.
    - Reduce to n_features dimensions (PCA if needed)
    - Scale to encoding range
    - Split train/test
    """
    # PCA reduction if needed
    if X.shape[1] > n_features:
        pca = PCA(n_components=n_features)
        X = pca.fit_transform(X)
        print(f"PCA explained variance: {pca.explained_variance_ratio_.sum():.3f}")

    # Scale based on encoding type
    if encoding == 'angle':
        scaler = MinMaxScaler(feature_range=(0, np.pi))
    elif encoding == 'amplitude':
        # Normalize to unit sphere
        norms = np.linalg.norm(X, axis=1, keepdims=True)
        X = X / (norms + 1e-10)
        scaler = None
    else:
        scaler = StandardScaler()

    if scaler is not None:
        X = scaler.fit_transform(X)

    # Train/test split
    X_tr, X_te, y_tr, y_te = train_test_split(
        X, y, test_size=test_size,
        stratify=y if len(np.unique(y)) > 1 else None,
        random_state=random_state
    )
    return X_tr, X_te, y_tr, y_te

# Example usage
from sklearn.datasets import load_breast_cancer
X, y = load_breast_cancer(return_X_y=True)
X_tr, X_te, y_tr, y_te = prepare_for_qml(X, y, n_features=4, encoding='angle')
print(f"Train: {X_tr.shape}, Test: {X_te.shape}")