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:
| Name | Description |
|---|
| train | Trains an SVM model using a custom precomputed kernel from the training data. |
| predict | Predicts labels for new data using a precomputed kernel with a trained SVM model. |
| test | Predicts the labels of the test dataset and evaluates the resulting test score using the ground-truth labels. |
| get_svm_model | Returns the classical SVM model. |
| get_qprog | Returns 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:
| Name | Type | Description | Default |
|---|
self | “ | | required |
train_data | np.ndarray | Contains the data points (np.ndarray) | required |
train_labels | np.ndarray | Contains 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:
| Name | Type | Description | Default |
|---|
self | “ | | required |
data | np.ndarray | List 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:
| Name | Type | Description | Default |
|---|
self | “ | | required |
data | np.ndarray | List of test data points to predict. | required |
data_labels | np.ndarray | Contains 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:
| Name | Type | Description | Default |
|---|
self | “ | | required |
get_qprog
get_qprog(
self:
) -> QuantumProgram | None
Returns the quantum program.
Parameters:
| Name | Type | Description | Default |
|---|
self | “ | | required |