Optimize a multiclass problem
QuOptuna handles binary and multiclass targets with different conventions:
| Binary | Multiclass | |
|---|---|---|
| Target encoding | {-1, +1} | codes 0..K-1 |
| Objective metric | binary F1 | macro-F1 |
| Variational quantum models | native | automatically OvR-wrapped (one-vs-rest, K binary sub-models) |
| Kernel / classical models | native | native |
Variational quantum models are automatically wrapped in one-vs-rest (OvR): K binary sub-models, one per class. Kernel and classical sklearn models handle multiclass natively without wrapping.
Run a 3-class problem (CLI)
Section titled “Run a 3-class problem (CLI)”Iris (--uci-id 53) has 3 classes and is a good smoke test:
quoptuna optimize --uci-id 53QuOptuna detects the number of classes, switches the objective to macro-F1, and OvR-wraps any variational quantum models in the search space.
Python path
Section titled “Python path”From Python, pass the raw target column — QuOptuna reads the class codes directly:
from quoptuna.backend.tuners.optimizer import Optimizer
Optimizer( study_name="iris-3class", db_name="iris", data=data, # raw target column with codes 0..K-1 model_types=models, search_space=space,).optimize(n_trials=100)Speed up OvR sub-fits
Section titled “Speed up OvR sub-fits”OvR sub-fits are serial by default. To fit the K binary sub-models concurrently on threads, set the environment variable:
export QUOPTUNA_OVR_N_JOBS=3 # = K, the number of classesThreads only — QuOptuna never uses processes here because pickling JAX models is unsafe.
Multiclass fairness
Section titled “Multiclass fairness”For fairness-aware multiclass search you must set favorable_class (which class code counts as the favorable outcome). See Run fairness-aware search.