當前位置: 首頁>>代碼示例>>Python>>正文


Python Node.classify方法代碼示例

本文整理匯總了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')
開發者ID:joshterrell805-historic,項目名稱:CPE466-KDD,代碼行數:27,代碼來源:test_model.py

示例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)
開發者ID:joshterrell805-historic,項目名稱:CPE466-KDD,代碼行數:14,代碼來源:test_model.py

示例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')
開發者ID:joshterrell805-historic,項目名稱:CPE466-KDD,代碼行數:26,代碼來源:test_model.py


注:本文中的model.Node.classify方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。