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: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:
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:
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:
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:
get_qprog
get_qprog(
self: ,
data_dim: int = 0
) -> QuantumProgram
Returns the quantum program for the kernel at data_dim feature width.
Parameters: