Skip to main content

QSVM

Quantum support vector machine (QSVM) model. Classifies classical data into two categories. The model is first trained, and fitted. After pre-training, the model predicts the labels of new data points. Methods:
NameDescription
trainTrains an SVM model using a custom precomputed kernel from the training data.
predictPredicts labels for new data using a precomputed kernel with a trained SVM model.
testPredicts the labels of the test dataset and evaluates the resulting test score using the ground-truth labels.
get_svm_modelReturns the classical SVM model.
get_qprogReturns the quantum program.

feature_map

feature_map = feature_map

num_qubits

num_qubits = num_qubits

execution_preferences

execution_preferences = execution_preferences

kernel_eval

kernel_eval = QuantumKernelEvaluator(feature_map=(self.feature_map), num_qubits=(self.num_qubits), execution_preferences=(self.execution_preferences))

model

model = SVC(kernel='precomputed')

train_data

train_data: np.ndarray | None = None

train

train(
self: ,
train_data: np.ndarray,
train_labels: np.ndarray
) -> None
Trains an SVM model using a custom precomputed kernel from the training data. Parameters:
NameTypeDescriptionDefault
selfrequired
train_datanp.ndarrayContains the data points (np.ndarray)required
train_labelsnp.ndarrayContains the labels (0,1).required

predict

predict(
self: ,
data: np.ndarray
) -> np.ndarray
Predicts labels for new data using a precomputed kernel with a trained SVM model. Evaluates kernel matrix elements which are associated with the support vectors (those associated with non-vanishing coefficients in the prediction equation). Parameters:
NameTypeDescriptionDefault
selfrequired
datanp.ndarrayList of new data points to predict.required
Returns:
  • Type: np.ndarray
  • np.ndarray: Predicted labels (0,1).

test

test(
self: ,
data: np.ndarray,
data_labels: np.ndarray
) -> tuple[float, np.ndarray]
Predicts the labels of the test dataset and evaluates the resulting test score using the ground-truth labels. Parameters:
NameTypeDescriptionDefault
selfrequired
datanp.ndarrayList of test data points to predict.required
data_labelsnp.ndarrayContains the test data labels.required
Returns:
  • Type: tuple[float, np.ndarray]
  • containing test score (float) and test labels (np.ndarray[int]).

get_svm_model

get_svm_model(
self:
) -> SVC
Returns the classical SVM model. Parameters:
NameTypeDescriptionDefault
selfrequired

get_qprog

get_qprog(
self:
) -> QuantumProgram | None
Returns the quantum program. Parameters:
NameTypeDescriptionDefault
selfrequired