def test_decision_tree_classification3(self):
        train_out = decision_tree_classification_train(table=self.iris,
                                                       feature_cols=[
                                                           'sepal_length',
                                                           'sepal_width',
                                                           'petal_length',
                                                           'petal_width'
                                                       ],
                                                       label_col='species',
                                                       random_state=12345,
                                                       criterion='entropy',
                                                       max_leaf_nodes=2,
                                                       group_by=['species'])
        predict_out = decision_tree_classification_predict(
            table=self.iris, model=train_out['model'])

        table = predict_out['out_table'].values.tolist()
        self.assertListEqual(table[0],
                             [5.1, 3.5, 1.4, 0.2, 'setosa', 'setosa'])
        self.assertListEqual(table[1],
                             [4.9, 3.0, 1.4, 0.2, 'setosa', 'setosa'])
        self.assertListEqual(table[2],
                             [4.7, 3.2, 1.3, 0.2, 'setosa', 'setosa'])
        self.assertListEqual(table[3],
                             [4.6, 3.1, 1.5, 0.2, 'setosa', 'setosa'])
        self.assertListEqual(table[4],
                             [5.0, 3.6, 1.4, 0.2, 'setosa', 'setosa'])
Exemple #2
0
 def test_groupby1(self):
     df = load_iris()
     random_group = []
     for _ in range(len(df)):
         random_group.append(random.randint(1, 2))
     df['random_group'] = random_group
     
     train_out = decision_tree_classification_train(table=df, feature_cols=['sepal_length', 'sepal_width', 'petal_length', 'petal_width'], label_col='species', group_by=['random_group'])
     predict_out = decision_tree_classification_predict(table=df, model=train_out['model'])
Exemple #3
0
    def groupby1(self):
        df = get_iris()
        random_group = []
        for i in range(len(df)):
            random_group.append(random.randint(1, 2))
        df['random_group'] = random_group

        train_out = decision_tree_classification_train(
            df,
            feature_cols=[
                'sepal_length', 'sepal_width', 'petal_length', 'petal_width'
            ],
            label_col='species',
            group_by=['random_group'])
        predict_out = decision_tree_classification_predict(
            df, train_out['model'])
        print(predict_out['out_table'][['species', 'prediction']])