当前位置: 首页>>代码示例>>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;未经允许,请勿转载。