dc045bebd58dbf547728ff2f34e1d9a0fcb916f9,test/aqua/test_qsvm.py,TestQSVM,test_qsvm_multiclass_one_against_all,#TestQSVM#,208
Before Change
def test_qsvm_multiclass_one_against_all(self):
QSVM Multiclass One Against All test
backend = BasicAer.get_backend("qasm_simulator")
training_input = {"A": np.asarray([[0.6560706, 0.17605998], [0.25776033, 0.47628296],
[0.8690704, 0.70847635]]),
"B": np.asarray([[0.38857596, -0.33775802], [0.49946978, -0.48727951],
[0.49156185, -0.3660534]]),
"C": np.asarray([[-0.68088231, 0.46824423], [-0.56167659, 0.65270294],
[-0.82139073, 0.29941512]])}
test_input = {"A": np.asarray([[0.57483139, 0.47120732], [0.48372348, 0.25438544],
[0.48142649, 0.15931707]]),
"B": np.asarray([[-0.06048935, -0.48345293], [-0.01065613, -0.33910828],
[0.06183066, -0.53376975]]),
"C": np.asarray([[-0.74561108, 0.27047295], [-0.69942965, 0.11885162],
[-0.66489165, 0.1181712]])}
total_array = np.concatenate((test_input["A"], test_input["B"], test_input["C"]))
params = {
"problem": {"name": "classification", "random_seed": self.random_seed},
"algorithm": {
"name": "QSVM",
},
"backend": {"shots": self.shots},
"multiclass_extension": {"name": "OneAgainstRest"},
"feature_map": {"name": "SecondOrderExpansion", "depth": 2, "entangler_map": [[0, 1]]}
}
algo_input = ClassificationInput(training_input, test_input, total_array)
result = run_algorithm(params, algo_input, backend=backend)
expected_accuracy = 0.444444444
expected_classes = ["A", "A", "C", "A", "A", "A", "A", "C", "C"]
self.assertAlmostEqual(result["testing_accuracy"], expected_accuracy, places=4)
After Change
def test_qsvm_multiclass_one_against_all(self):
QSVM Multiclass One Against All test
training_input = {"A": np.asarray([[0.6560706, 0.17605998], [0.25776033, 0.47628296],
[0.8690704, 0.70847635]]),
"B": np.asarray([[0.38857596, -0.33775802], [0.49946978, -0.48727951],
[0.49156185, -0.3660534]]),
"C": np.asarray([[-0.68088231, 0.46824423], [-0.56167659, 0.65270294],
[-0.82139073, 0.29941512]])}
test_input = {"A": np.asarray([[0.57483139, 0.47120732], [0.48372348, 0.25438544],
[0.48142649, 0.15931707]]),
"B": np.asarray([[-0.06048935, -0.48345293], [-0.01065613, -0.33910828],
[0.06183066, -0.53376975]]),
"C": np.asarray([[-0.74561108, 0.27047295], [-0.69942965, 0.11885162],
[-0.66489165, 0.1181712]])}
total_array = np.concatenate((test_input["A"], test_input["B"], test_input["C"]))
aqua_globals.random_seed = self.random_seed
feature_map = SecondOrderExpansion(feature_dimension=get_feature_dimension(training_input),
depth=2,
entangler_map=[[0, 1]])
svm = QSVM(feature_map, training_input, test_input, total_array,
multiclass_extension=OneAgainstRest(_QSVM_Estimator, [feature_map]))
quantum_instance = QuantumInstance(BasicAer.get_backend("qasm_simulator"), shots=self.shots)
result = svm.run(quantum_instance)
expected_accuracy = 0.444444444
expected_classes = ["A", "A", "C", "A", "A", "A", "A", "C", "C"]
self.assertAlmostEqual(result["testing_accuracy"], expected_accuracy, places=4)
self.assertEqual(result["predicted_classes"], expected_classes)
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 26
Instances
Project Name: Qiskit/qiskit-aqua
Commit Name: dc045bebd58dbf547728ff2f34e1d9a0fcb916f9
Time: 2019-11-08
Author: manoel@us.ibm.com
File Name: test/aqua/test_qsvm.py
Class Name: TestQSVM
Method Name: test_qsvm_multiclass_one_against_all
Project Name: Qiskit/qiskit-aqua
Commit Name: dc045bebd58dbf547728ff2f34e1d9a0fcb916f9
Time: 2019-11-08
Author: manoel@us.ibm.com
File Name: test/aqua/test_qsvm.py
Class Name: TestQSVM
Method Name: test_qsvm_multiclass_error_correcting_code
Project Name: Qiskit/qiskit-aqua
Commit Name: dc045bebd58dbf547728ff2f34e1d9a0fcb916f9
Time: 2019-11-08
Author: manoel@us.ibm.com
File Name: test/aqua/test_qsvm.py
Class Name: TestQSVM
Method Name: test_qsvm_multiclass_all_pairs
Project Name: Qiskit/qiskit-aqua
Commit Name: dc045bebd58dbf547728ff2f34e1d9a0fcb916f9
Time: 2019-11-08
Author: manoel@us.ibm.com
File Name: test/aqua/test_qsvm.py
Class Name: TestQSVM
Method Name: test_qsvm_multiclass_one_against_all