Skip to main contentIBM Quantum Documentation
You are viewing the API reference for an old version of Qiskit SDK. Switch to latest version

SklearnSVM

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

GitHub(opens in a new tab)

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(opens in a new tab) 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


Attributes

class_to_label

returns class to label

label_to_class

returns label to class

random

Return a numpy random.

ret

returns result


Methods

load_model

SklearnSVM.load_model(file_path)

Load a model from a file path.

Parameters

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

predict

SklearnSVM.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

run

SklearnSVM.run()

Execute the classical algorithm.

Returns

results of an algorithm.

Return type

dict

save_model

SklearnSVM.save_model(file_path)

Save the model to a file path.

Parameters

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

test

SklearnSVM.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

SklearnSVM.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.