def test_manyways(self): a = np.array([5, 7, 1, 2, 8]) b = np.array([9, 8, 2, 4, 3, 1, 5]) c1 = setxor1d(a, b) aux1 = intersect1d(a, b) aux2 = union1d(a, b) c2 = setdiff1d(aux2, aux1) assert_array_equal(c1, c2)
def test_setxor1d(self): a = np.array([5, 7, 1, 2]) b = np.array([2, 4, 3, 1, 5]) ec = np.array([3, 4, 7]) c = setxor1d(a, b) assert_array_equal(c, ec) a = np.array([1, 2, 3]) b = np.array([6, 5, 4]) ec = np.array([1, 2, 3, 4, 5, 6]) c = setxor1d(a, b) assert_array_equal(c, ec) a = np.array([1, 8, 2, 3]) b = np.array([6, 5, 4, 8]) ec = np.array([1, 2, 3, 4, 5, 6]) c = setxor1d(a, b) assert_array_equal(c, ec) assert_array_equal([], setxor1d([], []))
def RecursionTree(self, node, x, x_rows, y): #没有节点 if len(x_rows) <= 0: return #叶子节点 if node.HasChildren() == False: y[x_rows] = node.GetLabel() # logger.debug('predict 获取标签:%d,x_rows:%s', node.GetLabel(),x_rows) return feature = node.GetSplitAttr() rest_x_row = np.array(x_rows, dtype=np.int) for (value, child) in node.GetChildren(): new_x_row = np.intersect1d(x_rows, np.where(x[:, feature] == value)[0]) rest_x_row = arraysetops.setxor1d(rest_x_row, new_x_row, True) self.RecursionTree(child, x, new_x_row, y) #训练不充分导致测试集有未知数据不能向下划分预测 y[rest_x_row] = self.Classify(y, x_rows)