def test_kNearestDatasets(self): kND = KNearestDatasets() kND.fit(pd.DataFrame([self.krvskp, self.labor]), self.runs.loc[:, [233, 234]]) neighbor = kND.kNearestDatasets(self.anneal, 1) self.assertEqual([233], neighbor) neighbor, distance = kND.kNearestDatasets(self.anneal, 1, return_distance=True) self.assertEqual([233], neighbor) assert_array_almost_equal([1.82298937], distance) neighbors = kND.kNearestDatasets(self.anneal, 2) self.assertEqual([233, 234], neighbors) neighbors, distance = kND.kNearestDatasets(self.anneal, 2, return_distance=True) self.assertEqual([233, 234], neighbors) assert_array_almost_equal([1.822989, 2.267919], distance) neighbors = kND.kNearestDatasets(self.anneal, -1) self.assertEqual([233, 234], neighbors) neighbors, distance = kND.kNearestDatasets(self.anneal, -1, return_distance=True) self.assertEqual([233, 234], neighbors) assert_array_almost_equal([1.822989, 2.267919], distance) self.assertRaises(ValueError, kND.kNearestDatasets, self.anneal, 0) self.assertRaises(ValueError, kND.kNearestDatasets, self.anneal, -2)
def test_kNearestDatasets(self): kND = KNearestDatasets() kND.fit(pd.DataFrame([self.krvskp, self.labor]), self.runs.loc[:, [233, 234]]) neighbor = kND.kNearestDatasets(self.anneal, 1) self.assertEqual([233], neighbor) neighbor, distance = kND.kNearestDatasets(self.anneal, 1, return_distance=True) self.assertEqual([233], neighbor) np.testing.assert_array_almost_equal([3.8320802803440586], distance) neighbors = kND.kNearestDatasets(self.anneal, 2) self.assertEqual([233, 234], neighbors) neighbors, distance = kND.kNearestDatasets(self.anneal, 2, return_distance=True) self.assertEqual([233, 234], neighbors) np.testing.assert_array_almost_equal( [3.8320802803440586, 4.367919719655942], distance) neighbors = kND.kNearestDatasets(self.anneal, -1) self.assertEqual([233, 234], neighbors) neighbors, distance = kND.kNearestDatasets(self.anneal, -1, return_distance=True) self.assertEqual([233, 234], neighbors) np.testing.assert_array_almost_equal( [3.8320802803440586, 4.367919719655942], distance) self.assertRaises(ValueError, kND.kNearestDatasets, self.anneal, 0) self.assertRaises(ValueError, kND.kNearestDatasets, self.anneal, -2)