本文整理匯總了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')