本文整理汇总了Python中Node.Node.index方法的典型用法代码示例。如果您正苦于以下问题:Python Node.index方法的具体用法?Python Node.index怎么用?Python Node.index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node.Node
的用法示例。
在下文中一共展示了Node.index方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildIndex
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import index [as 别名]
def buildIndex(self):
"""build the htree & grid structure. htree is a high fanout and low level tree"""
budget_c = self.getCountBudget() # an array with two elements
self.root.n_count = self.getCount(self.root, 0) # add noisy count to the root
queue = deque()
queue.append(self.root)
nleaf = 0 # number of leaf node, for debug only
# ## main loop
while len(queue) > 0:
curr = queue.popleft()
if self.testLeaf(curr) is True: # if curr is a leaf node
if curr.n_depth < self.param.maxHeightHTree:
remainingEps = sum(budget_c[curr.n_depth:])
curr.n_count = self.getCount(curr, remainingEps)
curr.eps = remainingEps
nleaf += 1
curr.n_isLeaf = True
else: # curr needs to split
split_arr, n_data_arr = self.getCoordinates(curr)
if split_arr is None:
if curr.n_depth < self.param.maxHeightHTree:
remainingEps = sum(budget_c[curr.n_depth:])
curr.n_count = self.getCount(curr, remainingEps)
curr.eps = remainingEps
nleaf += 1
curr.n_isLeaf = True
curr.children = []
continue # if the first level cell is leaf node
for i in range(len(n_data_arr)):
node = Node()
if curr.n_depth % Params.NDIM == 0: # split by x coord
node.n_box = np.array([[split_arr[i], curr.n_box[0, 1]], [split_arr[i + 1], curr.n_box[1, 1]]])
else: # split by y coord
node.n_box = np.array([[curr.n_box[0, 0], split_arr[i]], [curr.n_box[1, 0], split_arr[i + 1]]])
node.index = i
node.parent = curr
node.n_depth = curr.n_depth + 1
node.n_data = n_data_arr[i]
node.n_count = self.getCount(node, budget_c[node.n_depth])
if n_data_arr[i] is None:
node.a_count = 0
else:
node.a_count = n_data_arr[i].shape[1]
node.eps = budget_c[node.n_depth]
if curr.n_depth == 2:
node.secondLevelPartitions = curr.secondLevelPartitions
curr.children.append(node)
queue.append(node)
# if curr.n_depth == 2:
# self.children.append(curr)
curr.n_data = None # ## do not need the data points coordinates now
# end of while
logging.debug("Generic: number of leaves: %d" % nleaf)
示例2: build_dt
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import index [as 别名]
def build_dt(attri_indices, obj_indices):
"""
:param attri_indices: Set of indices of attributes for this subtree.
:param obj_indices: Set of indices of objects for this subtree.
:return: Root of this decision tree constructed from data as stated above.
"""
if len(obj_indices) == 0:
raise RuntimeError('No objects in this node')
else:
node = Node()
# If all attributes have been used in this path make this node a leaf node.
if len(attri_indices) == 0:
node.result = find_majority(Data.train[obj_indices, 0])
return node
# If target in this subset of data is pure, make this node a leaf node.
elif entropy(Data.train[obj_indices, 0]) == 0:
node.result = Data.train[obj_indices[0]][0]
return node
# Find the best attribute for splitting and split the data set with that attribute
else:
if len(attri_indices) == 1:
selected_index = attri_indices[0]
else:
selected_index = gain_info_select(attri_indices, obj_indices)
node.index = selected_index
subsets = split_obj(selected_index, obj_indices, 'train')
if not chi_square_test(obj_indices, subsets):
node.result = find_majority(Data.train[obj_indices, 0])
return node
attri_subset = delete_index(attri_indices, selected_index)
# Build subtrees with subsets of data
for subset in subsets:
# Make the empty subset corresponding to some attribute a leaf node
if len(subset) == 0:
new_child = Node()
new_child.result = find_majority(Data.train[obj_indices, 0])
node.child.append(new_child)
else:
node.child.append(build_dt(attri_subset, subset))
return node
示例3: buildIndex
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import index [as 别名]
def buildIndex(self):
self.root.n_count = self.getCount(self.root)
queue = deque()
queue.append(self.root)
nleaf = 0 # number of leaf node, for debug only
# ## main loop
while len(queue) > 0:
curr = queue.popleft()
if self.testLeaf(curr) is True: # if curr is a leaf node
if curr.n_depth < self.param.maxHeightHTree:
curr.n_count = self.getCount(curr)
curr.n_isLeaf = True
else: # curr needs to split
split_arr, n_data_arr = self.getCoordinates(curr)
if split_arr is None:
if curr.n_depth < self.param.maxHeightHTree:
curr.n_count = self.getCount(curr)
curr.n_isLeaf = True
curr.children = []
continue # if the first level cell is leaf node
for i in range(len(n_data_arr)):
node = Node()
if curr.n_depth % self.param.NDIM == 0: # split by x coord
node.n_box = np.array([[split_arr[i], curr.n_box[0, 1]], [split_arr[i + 1], curr.n_box[1, 1]]])
else: # split by y coord
node.n_box = np.array([[curr.n_box[0, 0], split_arr[i]], [curr.n_box[1, 0], split_arr[i + 1]]])
node.index = i
node.parent = curr
node.n_depth = curr.n_depth + 1
node.n_data = n_data_arr[i]
node.n_count = self.getCount(node)
curr.children.append(node)
queue.append(node)
curr.n_data = None # ## do not need the data points coordinates now