Skip to content

Optimize a multiclass problem

QuOptuna handles binary and multiclass targets with different conventions:

BinaryMulticlass
Target encoding{-1, +1}codes 0..K-1
Objective metricbinary F1macro-F1
Variational quantum modelsnativeautomatically OvR-wrapped (one-vs-rest, K binary sub-models)
Kernel / classical modelsnativenative

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.

Iris (--uci-id 53) has 3 classes and is a good smoke test:

Terminal window
quoptuna optimize --uci-id 53

QuOptuna detects the number of classes, switches the objective to macro-F1, and OvR-wraps any variational quantum models in the search space.

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)

OvR sub-fits are serial by default. To fit the K binary sub-models concurrently on threads, set the environment variable:

Terminal window
export QUOPTUNA_OVR_N_JOBS=3 # = K, the number of classes

Threads only — QuOptuna never uses processes here because pickling JAX models is unsafe.

For fairness-aware multiclass search you must set favorable_class (which class code counts as the favorable outcome). See Run fairness-aware search.