本文整理汇总了Python中tree.Node.choose_best_attr方法的典型用法代码示例。如果您正苦于以下问题:Python Node.choose_best_attr方法的具体用法?Python Node.choose_best_attr怎么用?Python Node.choose_best_attr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Node
的用法示例。
在下文中一共展示了Node.choose_best_attr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: return
# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import choose_best_attr [as 别名]
f.close()
return (training_data, validation_data, test_data)
training_data, validation_data, test_data = load_data()
X, y = training_data[0], training_data[1]
X_v, y_v = validation_data[0], validation_data[1]
X_t, y_t = test_data[0], test_data[1]
# Test before split entropy calculated when init
node = Node(X_t[:100, :], y_t[:100], verbose=True)
assert node.before_split_entropy is not None
# Test choose best attr
t1 = time.time()
node.choose_best_attr()
t2 = time.time()
print "time: %s" % (t2 - t1)
assert node.best_attr_index is not None
assert node.best_threshold is not None
print node.best_attr_index, node.best_threshold
# Test tree generation
indices = [i for i in np.random.choice(X.shape[0], 5000)]
X_tree = np.array([X[i, :] for i in indices])
y_tree = np.array([y[i] for i in indices])
t1 = time.time()
tree = Tree(X_tree, y_tree)