Skip to content

qsvr

eigenkit.qml.qsvr

eigenkit.qml.qsvr.QSVR

Bases: BaseQuantumRegressor

Quantum support vector regressor (QSVR).

It is the regression counterpart of QSVC. It uses SVR(kernel="precomputed") from scikit-learn on the quantum kernel matrix.

Parameters:

Name Type Description Default
feature_map str

The feature map. It is "Angle" (angle encoding into a product state) or "AngleCNOT" (angle encoding with ladders of controlled-NOT (CNOT) gates). Default: "Angle". It is ignored when kernel is given.

'Angle'
reps int

The number of repetitions of the feature map. Default: 1. It is ignored when kernel is given.

1
C float

The regularisation parameter of the support vector regressor. Default: 1.0.

1.0
epsilon float

The width of the epsilon-insensitive tube. Default: 0.1.

0.1
provider ProviderSpec

The backend. It takes the same options as Circuit(provider=...). Default: "numpy". It is ignored when kernel is given.

'numpy'
random_state int | None

The seed.

42
kernel QuantumKernel | None

A QuantumKernel to use instead of building one from feature_map, reps and provider. Default: None.

None
scale float

The bandwidth. The inputs are multiplied by it before they reach the kernel. Default: 1.0.

1.0
Example
import numpy as np
from eigenkit import QSVR

rng = np.random.default_rng(0)
X_train, X_test = rng.uniform(0, np.pi, (8, 2)), rng.uniform(0, np.pi, (3, 2))
y_train = np.sin(X_train).sum(axis=1)

model = QSVR(feature_map="Angle", reps=1)
model.fit(X_train, y_train)
predictions = model.predict(X_test)

fit(X, y)

Fit the regressor on training data.

Parameters:

Name Type Description Default
X ndarray

The samples, of shape (n_samples, n_features).

required
y ndarray

The float targets, of shape (n_samples,).

required

Returns:

Type Description
QSVR

This estimator, so that calls can be chained.

load(path, *, provider=None, trusted=False) classmethod

Load a fitted model from a .eigenkit bundle.

Loading a bundle does not unpickle anything, unless you pass trusted=True for a bundle saved before eigenkit 1.3.

Parameters:

Name Type Description Default
path str | Path

The path of the bundle.

required
provider ProviderSpec | None

A provider that replaces the saved one.

None
trusted bool

Load a bundle saved before eigenkit 1.3 by QSVC, QSVR or the reservoir classifier. Such a bundle holds joblib pickles, and unpickling runs code, as with torch.load or joblib.load. Pass it only for bundles whose source you trust, and save the model again to store it without pickles.

False

Returns:

Type Description
'BaseQuantumEstimator'

The loaded estimator.

Raises:

Type Description
TypeError

If the method is called on a subclass and the bundle holds a different class. BaseQuantumEstimator.load() accepts any class.

SerializationError

If the bundle holds joblib pickles and trusted is False.

predict(X)

Predict continuous targets for X.

Parameters:

Name Type Description Default
X ndarray

The samples, of shape (n_samples, n_features).

required

Returns:

Type Description
ndarray

One prediction for each sample.

save(path)

Save a fitted model to a .eigenkit bundle.

A bundle holds JSON, NumPy arrays without pickle, PyTorch weights and, for models built on scikit-learn objects (QSVC, QSVR, the reservoir classifier), those objects serialized with skops. None of them is a pickle, so loading a bundle does not run code from it.

Parameters:

Name Type Description Default
path str | Path

The path of the bundle. The suffix .eigenkit is added when it is missing.

required