Tamil
மொழிகள்
English
Bengali
French
Hindi
Japanese
Korean
Russian
Spanish
Tamil
Turkish



PegasosQSVC

class PegasosQSVC(quantum_kernel=None, C=1.0, num_steps=1000, precomputed=False, seed=None)[source]

Bases: ClassifierMixin, SerializableModelMixin

Implements Pegasos Quantum Support Vector Classifier algorithm. The algorithm has been developed in [1] and includes methods fit, predict and decision_function following the signatures of sklearn.svm.SVC. This implementation is adapted to work with quantum kernels.

Example

quantum_kernel = FidelityQuantumKernel()

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.

Pegasos for SVM

Parameters:
  • quantum_kernel (BaseKernel | None) -- a quantum kernel to be used for classification. Has to be None when a precomputed kernel is used.

  • C (float) -- Positive regularization parameter. The strength of the regularization is inversely proportional to C. Smaller C induce smaller weights which generally helps preventing overfitting. However, due to the nature of this algorithm, some of the computation steps become trivial for larger C. Thus, larger C 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 to True in case of precomputed kernel.

  • seed (int | None) -- a seed for the random number generator

Raises:
  • ValueError --

    • if quantum_kernel is passed and precomputed is set to True. To use a precomputed kernel, quantum_kernel has to be of the None type.

  • TypeError --

    • if quantum_kernel neither instance of BaseKernel nor None.

Attributes

FITTED

UNFITTED

num_steps

Returns number of steps in the Pegasos algorithm.

precomputed

Returns a boolean flag indicating whether a precomputed kernel is used.

quantum_kernel

Returns quantum kernel

Methods

decision_function(X)

Evaluate the decision function for the samples in X.

fit(X, y[, sample_weight])

Fit the model according to the given training data.

load(file_name)

Loads a model from the file.

predict(X)

Perform classification on samples in X.

save(file_name)

Saves this model to the specified file.

score(X, y[, sample_weight])

Return the mean accuracy on the given test data and labels.