Skip to main contentIBM Quantum Documentation
This page is from an old version of Qiskit SDK and does not exist in the latest version. We recommend you migrate to the latest version. See the release notes for more information.

qiskit.aqua.algorithms.SklearnSVM

class SklearnSVM(training_dataset, test_dataset=None, datapoints=None, gamma=None, multiclass_extension=None)

GitHub

The Sklearn SVM algorithm (classical).

This scikit-learn based SVM algorithm uses a classical approach to experiment with feature map classification problems. See also the quantum classifier QSVM.

Internally, this algorithm will run the binary classification or multiclass classification based on how many classes the data has. If the data has more than 2 classes then a multiclass_extension is required to be supplied. Aqua provides several multiclass_extensions.

Parameters

  • training_dataset (Dict[str, ndarray]) – Training dataset.
  • test_dataset (Optional[Dict[str, ndarray]]) – Testing dataset.
  • datapoints (Optional[ndarray]) – Prediction dataset.
  • gamma (Optional[int]) – Used as input for sklearn rbf_kernel which is used internally. See sklearn.metrics.pairwise.rbf_kernel for more information about gamma.
  • multiclass_extension (Optional[MulticlassExtension]) – If number of classes is greater than 2 then a multiclass scheme must be supplied, in the form of a multiclass extension.

Raises

AquaError – Multiclass extension not supplied when number of classes > 2

__init__

__init__(training_dataset, test_dataset=None, datapoints=None, gamma=None, multiclass_extension=None)

Parameters

  • training_dataset (Dict[str, ndarray]) – Training dataset.

  • test_dataset (Optional[Dict[str, ndarray]]) – Testing dataset.

  • datapoints (Optional[ndarray]) – Prediction dataset.

  • gamma (Optional[int]) –

    Used as input for sklearn rbf_kernel which is used internally. See sklearn.metrics.pairwise.rbf_kernel for more information about gamma.

  • multiclass_extension (Optional[MulticlassExtension]) – If number of classes is greater than 2 then a multiclass scheme must be supplied, in the form of a multiclass extension.

Raises

AquaError – Multiclass extension not supplied when number of classes > 2


Methods

__init__(training_dataset[, test_dataset, …])type training_datasetDict[str, ndarray]
load_model(file_path)Load a model from a file path.
predict(data)Predict using the SVM
run()Execute the classical algorithm.
save_model(file_path)Save the model to a file path.
test(data, labels)Test the SVM
train(data, labels)Train the SVM

Attributes

class_to_labelreturns class to label
label_to_classreturns label to class
randomReturn a numpy random.
retreturns result

class_to_label

returns class to label

label_to_class

returns label to class

load_model

load_model(file_path)

Load a model from a file path.

Parameters

file_path (str) – the path of the saved model.

predict

predict(data)

Predict using the SVM

Parameters

data (numpy.ndarray) – NxD array, where N is the number of data, D is the feature dimension.

Returns

predicted labels, Nx1 array

Return type

numpy.ndarray

random

Return a numpy random.

ret

returns result

run

run()

Execute the classical algorithm.

Returns

results of an algorithm.

Return type

dict

save_model

save_model(file_path)

Save the model to a file path.

Parameters

file_path (str) – a path to save the model.

test

test(data, labels)

Test the SVM

Parameters

  • data (numpy.ndarray) – NxD array, where N is the number of data, D is the feature dimension.
  • labels (numpy.ndarray) – Nx1 array, where N is the number of data

Returns

accuracy

Return type

float

train

train(data, labels)

Train the SVM

Parameters

  • data (numpy.ndarray) – NxD array, where N is the number of data, D is the feature dimension.
  • labels (numpy.ndarray) – Nx1 array, where N is the number of data
Was this page helpful?
Report a bug or request content on GitHub.