本文整理汇总了Python中tree.Tree.predict方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.predict方法的具体用法?Python Tree.predict怎么用?Python Tree.predict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Tree
的用法示例。
在下文中一共展示了Tree.predict方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_estimator
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import predict [as 别名]
def init_estimator(self):
indices = [i for i in np.random.choice(X.shape[0], self.n_samples, p=self.weights)]
X_tree = np.array([X[i, :] for i in indices])
y_tree = np.array([y[i] for i in indices])
print "%s / %s" % (self.count, self.n_estimators)
while True:
t1 = time.time()
tree = Tree(X_tree, y_tree)
t2 = time.time()
print "tree generation time: %s" % (t2 - t1)
predictions = tree.predict(self.X)
accuracy = accuracy_score(self.y, predictions)
print "accuracy: %s" % accuracy
if accuracy != 0.50:
self.estimators.append(tree)
break
return tree, predictions
示例2: Tree
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import predict [as 别名]
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)
t2 = time.time()
print "time: %s" % (t2 - t1)
predictions = tree.predict(X_v)
accuracy_score(y_v, predictions)
# Test boost
boosting = Boosting(X, y, n_estimators=128, n_samples=2048)
boosting.train()
predictions = boosting.predict(X_v)
accuracy_score(y_v, predictions)