<jupyter_start><jupyter_text>_*SVM with a classical RBF kernel: multiclass classifier extension*_A multiclass extension works in conjunction with an underlying binary (two class) classifier to provide multiclass classification.Currently three different multiclass extensions are supported:* OneAgainstRest* AllPairs* ErrorCorrectingCodeThese use different techniques to group the data with binary classification to achieve the final multiclass classification.<jupyter_code>from datasets import *
from qiskit.aqua.utils import split_dataset_to_data_and_labels
from qiskit.aqua.input import ClassificationInput
from qiskit.aqua import run_algorithm
import numpy as np<jupyter_output><empty_output><jupyter_text>Here we choose the `Wine` dataset which has 3 classes.<jupyter_code>feature_dim = 2  # dimension of each data point
sample_Total, training_input, test_input, class_labels = Wine(training_size=20,
                                                              test_size=10, n=feature_dim, PLOT_DATA=True)

temp = [test_input[k] for k in test_input]
total_array = np.concatenate(temp)<jupyter_output><empty_output><jupyter_text>Now we setup an Aqua configuration dictionary to use the classical `SVM` algorithm and add a multiclass extension to classify the Wine data set, since it has 3 classes. We loop over the three extensions (modifying the params dictionary) to show the result with each.<jupyter_code>aqua_dict = {
    'problem': {'name': 'classification'},
    'algorithm': {
        'name': 'SVM'
    },
    'multiclass_extension': {'name': 'OneAgainstRest'}
}

algo_input = ClassificationInput(training_input, test_input, total_array)

extensions = [
   {'name': 'OneAgainstRest'},
   {'name': 'AllPairs'}, 
   {'name': 'ErrorCorrectingCode', 'code_size': 5}
]

for extension in extensions:
    aqua_dict['multiclass_extension'] = extension
    result = run_algorithm(aqua_dict, algo_input)
    print("\n----- Using multiclass extension: '{}' -----\n".format(extension['name']))
    for k,v in result.items():
        print("'{}' : {}".format(k, v))<jupyter_output>----- Using multiclass extension: 'OneAgainstRest' -----

'testing_accuracy' : 1.0
'test_success_ratio' : 1.0
'predicted_labels' : [0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2]
'predicted_classes' : ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C']

----- Using multiclass extension: 'AllPairs' -----

'testing_accuracy' : 1.0
'test_success_ratio' : 1.0
'predicted_labels' : [0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2]
'predicted_classes' : ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C']

----- Using multiclass extension: 'ErrorCorrectingCode' -----

'testing_accuracy' : 1.0
'test_success_ratio' : 1.0
'predicted_labels' : [0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2]
'predicted_classes' : ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', [...]
{'fraction_non_alphanumeric': 0.1646677471636953, 'fraction_numerical': 0.03565640194489465, 'mean_word_length': 4.0756578947368425, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '106626', 'license': 'Apache-2.0', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1056, 'n_words': 376, 'path': 'artificial_intelligence/svm_classical_multiclass.ipynb', 'repo_name': 'lukasszz/qiskit-tutorials-community', 'size': '3085'}