PegasosQSVC¶
- class PegasosQSVC(quantum_kernel=None, C=1.0, num_steps=1000, precomputed=False, seed=None)[source]¶
Bases :
SVC
,SerializableModelMixin
This class implements Pegasos Quantum Support Vector Classifier algorithm developed in [1] and includes overridden methods
fit
andpredict
from theSVC
super-class. This implementation is adapted to work with quantum kernels.Example
quantum_kernel = QuantumKernel() pegasos_qsvc = PegasosQSVC(quantum_kernel=quantum_kernel) pegasos_qsvc.fit(sample_train, label_train) pegasos_qsvc.predict(sample_test)
- References
- [1]: Shalev-Shwartz et al., Pegasos: Primal Estimated sub-GrAdient SOlver for SVM.
- Paramètres
quantum_kernel (
Optional
[QuantumKernel
]) – QuantumKernel to be used for classification. Has to beNone
when a precomputed kernel is used.C (
float
) – Positive regularization parameter. The strength of the regularization is inversely proportional to C. SmallerC
induce smaller weights which generally helps preventing overfitting. However, due to the nature of this algorithm, some of the computation steps become trivial for largerC
. Thus, largerC
improve the performance of the algorithm drastically. If the data is linearly separable in feature space,C
should be chosen to be large. If the separation is not perfect,C
should be chosen smaller to prevent overfitting.num_steps (
int
) – number of steps in the Pegasos algorithm. There is no early stopping criterion. The algorithm iterates over all steps.precomputed (
bool
) – a boolean flag indicating whether a precomputed kernel is used. Set it toTrue
in case of precomputed kernel.seed (
Optional
[int
]) – a seed for the random number generator
- Lève
if
quantum_kernel
is passed andprecomputed
is set toTrue
. To use a precomputed kernel,quantum_kernel
has to be of theNone
type.
if
quantum_instance
neither instance ofQuantumKernel
norNone
.
Attributes
Returns number of steps in the Pegasos algorithm.
Returns a boolean flag indicating whether a precomputed kernel is used.
Returns quantum kernel
Methods
fit
(X, y[, sample_weight])Fit the model according to the given training data.
predict
(X)Perform classification on samples in X.