def test_all_equal(self): eq = Equilateral(10, -1, 1) compare_dist = -1 for x in range(0, 10): base_class = eq.encode(x) for y in range(0, 10): if x != y: otherClass = eq.encode(y) dist = distance.euclidean(base_class, otherClass) if compare_dist < 0: compare_dist = dist else: self.assertAlmostEqual(dist, compare_dist, 7)
def norm_col_equilateral(self, data_set, col, classes, normalized_low, normalized_high): """ Normalize a column using equilateral. The classes parameter contains a map of the unique items in the specified column. Typically this value is obtained by calling build_class_map. """ col = self.resolve_column(col) eq = Equilateral(len(classes), normalized_low, normalized_high) for row in data_set: key = row[col] value = classes[key] row.pop(col) vec = eq.encode(value) for i in range(0, len(vec)): row.insert(col + i, vec[i])
def test_equilateral(self): eq = Equilateral(3, -1, 1) d = eq.encode(1); self.assertAlmostEqual(0.8660254037844386, d[0], 7) self.assertAlmostEqual(-0.5, d[1], 7)