def test_empty_kernel(self): """ Test QSVR with empty QuantumKernel """ qkernel = QuantumKernel() qsvr = QSVR(quantum_kernel=qkernel) with self.assertRaises(QiskitMachineLearningError): _ = qsvr.fit(self.sample_train, self.label_train)
def test_qsvr(self): """ Test QSVR """ qkernel = QuantumKernel(feature_map=self.feature_map, quantum_instance=self.statevector_simulator) qsvr = QSVR(quantum_kernel=qkernel) qsvr.fit(self.sample_train, self.label_train) score = qsvr.score(self.sample_test, self.label_test) self.assertAlmostEqual(score, 0.38365, places=4)
def test_qsvr_parameters(self): """Test QSVR with extra constructor parameters """ qkernel = QuantumKernel(feature_map=self.feature_map, quantum_instance=self.statevector_simulator) qsvr = QSVR(quantum_kernel=qkernel, tol=1e-4, C=0.5) qsvr.fit(self.sample_train, self.label_train) score = qsvr.score(self.sample_test, self.label_test) self.assertAlmostEqual(score, 0.38365, places=4)