forked from chunfuchen/aqua-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quantumsvm_multiclass_one_against_rest.py
48 lines (38 loc) · 1.5 KB
/
quantumsvm_multiclass_one_against_rest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
# Copyright 2018 IBM.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =============================================================================
import sys
from datasets import *
from qiskit_acqua.svm.data_preprocess import *
from qiskit_acqua.input import get_input_instance
from qiskit_acqua import run_algorithm
sample_Total, training_input, test_input, class_labels = \
Wine(training_size=40, test_size=10, n=2, # 2 is the dimension of each data point
PLOT_DATA=False)
total_array, label_to_labelclass = get_points(test_input, class_labels)
params = {
'problem': {'name': 'svm_classification'},
'backend': {'name': 'local_qasm_simulator', 'shots': 1000},
'algorithm': {
'name': 'QuantumSVM_OneAgainstRest',
'print_info': True
}
}
algo_input = get_input_instance('SVMInput')
algo_input.training_dataset = training_input
algo_input.test_dataset = test_input
algo_input.datapoints = total_array
result = run_algorithm(params, algo_input)
print(result)