本文整理汇总了Python中tree.Tree.nodeVal方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.nodeVal方法的具体用法?Python Tree.nodeVal怎么用?Python Tree.nodeVal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Tree
的用法示例。
在下文中一共展示了Tree.nodeVal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeTree
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import nodeVal [as 别名]
def makeTree(self, Mat, Tag):
miniumn = + numpy.inf
opt_feature = 0
opt_val = 0
Tag = numpy.array(Tag)
#return the type of data, if there is no different type of data
if numpy.unique(Tag).size == 1:
t = Tree()
t.isLeaf = True
t.nodeVal = Tag[0]
for label in self.labels:
if label != Tag[0]:
t.counter[label] = 0.0
else:
t.counter[label] = 1.0
return t
minium = + numpy.inf
for f in range(self.SamplesDem):
for i in range(len(Tag)):
v = Mat[f, i]
p = self.Gini(Mat[f], Tag, v, f)
p /= self.W[toHashableVal(Mat[:, i])]
if p < miniumn:
miniumn = p
opt_feature = f
opt_val = v
t = Tree()
t.nodeVal = opt_val
t.selFeature = opt_feature
if self.currentDepth == self.limitedDepth:
t.isLeaf = True
for label in self.labels:
t.counter[label] = 0
summer = 0.0
for i in range(len(Tag)):
label = Tag[i]
t.counter[label] += self.W[toHashableVal(Mat[:, i])]
summer += self.W[toHashableVal(Mat[:, i])]
for label in numpy.unique(Tag):
t.counter[label] /= summer
return t
if miniumn == 1:
return Tag[0]
self.currentDepth += 1
if self.Discrete[opt_feature] == True:
t.left = self.makeTree(
Mat[:, Mat[opt_feature, :] == opt_val],
Tag[ Mat[opt_feature, :] == opt_val])
t.right = self.makeTree(
Mat[:, Mat[opt_feature, :] != opt_val],
Tag[ Mat[opt_feature, :] != opt_val])
else:
t.left = self.makeTree(
Mat[:, Mat[opt_feature, :] < opt_val],
Tag[ Mat[opt_feature, :] < opt_val])
t.right = self.makeTree(
Mat[:, Mat[opt_feature, :] >= opt_val],
Tag[ Mat[opt_feature, :] >= opt_val])
return t