本文整理汇总了Python中model.Node.classify方法的典型用法代码示例。如果您正苦于以下问题:Python Node.classify方法的具体用法?Python Node.classify怎么用?Python Node.classify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Node
的用法示例。
在下文中一共展示了Node.classify方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_classify_success
# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import classify [as 别名]
def test_classify_success(self):
tree = Node("Gender",
("Female", Node("Bush Approval",
("Approve", Label("McCain")),
("Disapprove", Label("Obama")))),
("Male", Node("Ideology",
("Liberal", Label("Obama")),
("Moderate", Label("Obama")),
("Conservative", Label("McCain")))))
c = tree.classify(['Female', 'Approve', None],
['Gender', 'Bush Approval', 'Ideology'])
self.assertEqual(c, 'McCain')
# same but dif order of features
c = tree.classify(['Approve', 'Female', None],
['Bush Approval', 'Gender', 'Ideology'])
self.assertEqual(c, 'McCain')
# dif last node
c = tree.classify(['Disapprove', 'Female', None],
['Bush Approval', 'Gender', 'Ideology'])
self.assertEqual(c, 'Obama')
# dif first node
c = tree.classify([None, 'Male', 'Liberal'],
['Bush Approval', 'Gender', 'Ideology'])
self.assertEqual(c, 'Obama')
示例2: test_classify_invalid_value_for_column
# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import classify [as 别名]
def test_classify_invalid_value_for_column(self):
tree = Node("Gender",
("Female", Node("Bush Approval",
("Approve", Label("McCain")),
("Disapprove", Label("Obama")))),
("Male", Node("Ideology",
("Liberal", Label("Obama")),
("Moderate", Label("Obama")),
("Conservative", Label("McCain")))))
result = tree.classify(['Male', -1, -1], ['Gender', 'Ideology', 'c'])
self.assertIsNone(result)
示例3: test_classify_feature_names_do_not_match_tree
# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import classify [as 别名]
def test_classify_feature_names_do_not_match_tree(self):
tree = Node("Gender",
("Female", Node("Bush Approval",
("Approve", Label("McCain")),
("Disapprove", Label("Obama")))),
("Male", Node("Ideology",
("Liberal", Label("Obama")),
("Moderate", Label("Obama")),
("Conservative", Label("McCain")))))
try:
tree.classify(['Male', -1, -1], ['a', 'b', 'c'])
self.assertTrue(False)
except Exception as e:
self.assertEqual(
str(e),
'Datapoint does not fit tree: "Gender" not in features')
try:
tree.classify(['Male', 'Liberal', -1], ['Gender', 'b', 'c'])
self.assertTrue(False)
except Exception as e:
self.assertEqual(
str(e),
'Datapoint does not fit tree: "Ideology" not in features')