Esempio n. 1
0
    def test_seed(self):
        seed = 195
        dtree1 = dt.DecisionTree(max_features=1, seed=seed)
        dtree2 = dt.DecisionTree(max_features=1, seed=seed)
        dtree1.fit(X_TRAIN, self.labels_train)
        dtree2.fit(X_TRAIN, self.labels_train)

        for desc1, desc2 in zip(dtree1.tree.descendents(),
                                dtree2.tree.descendents()):
            assert desc1.split == desc2.split
Esempio n. 2
0
    def setup(self):
        self.x_train = X_TRAIN.copy()
        self.x_test = X_TEST.copy()

        self.x_train[:, 2] = -0.5 + self.labels_train
        self.x_test[:, 2] = -0.5 + self.labels_test

        self.dtree = dt.DecisionTree()
        self.dtree.fit(self.x_train, self.labels_train)
Esempio n. 3
0
    def test_copy(self):
        dtree1 = dt.DecisionTree()
        dtree1.fit(X_TRAIN, self.labels_train)
        dtree2 = dtree1.copy()

        assert dtree1.tree is not dtree2.tree
        for desc1, desc2 in zip(dtree1.tree.descendents(),
                                dtree2.tree.descendents()):
            assert desc1.split == desc2.split
Esempio n. 4
0
    def setup(self):
        self.x_train = X_TRAIN.copy()
        self.x_test = X_TEST.copy()

        self.x_train[:, 2] = np.abs(
            self.x_train[:, 2]) * (-1 + 2 * self.labels_train)
        self.x_test[:, 2] = np.abs(
            self.x_test[:, 2]) * (-1 + 2 * self.labels_test)

        self.dtree = dt.DecisionTree()
        self.dtree.fit(self.x_train, self.labels_train)
Esempio n. 5
0
    def test_params(self):
        param_dict = {
            'min_obs_split': 4,
            'max_depth': 2,
            'objfunc': metrics.gini,
            'max_features': 2,
            'seed': 153
        }

        dtree = dt.DecisionTree(**param_dict)
        for key, val in param_dict.items():
            assert dtree.params[key] == val
Esempio n. 6
0
    def setup(self):
        self.x_train = X_TRAIN.copy()
        self.x_test = X_TEST.copy()

        self.x_train[:, 2] = (
            -0.5 + self.labels_train +
            np.logical_and(self.labels_train, self.x_train[:, 2] > 0))
        self.x_test[:, 2] = (
            -0.5 + self.labels_test +
            np.logical_and(self.labels_test, self.x_test[:, 2] > 0))

        self.dtree = dt.DecisionTree()
        self.dtree.fit(self.x_train, self.labels_train)
Esempio n. 7
0
    def test_params_empty(self):
        param_dict = {
            'min_obs_split': None,
            'max_depth': None,
            'objfunc': metrics.gini,
            'max_features': None,
            'seed': None
        }

        dtree = dt.DecisionTree(**param_dict)
        for key, val in param_dict.items():
            if key == 'max_depth':
                assert dtree.params[key] == np.inf
            else:
                assert dtree.params[key] == val
Esempio n. 8
0
 def test_max_features_outofrange2(self):
     dtree = dt.DecisionTree(max_depth=1, max_features=-1)
     dtree.fit(X_TRAIN, self.labels_train)
Esempio n. 9
0
 def test_max_features_inrange(self):
     dtree = dt.DecisionTree(max_depth=1, max_features=2)
     dtree.fit(X_TRAIN, self.labels_train)
Esempio n. 10
0
 def test_fit(self):
     dtree = dt.DecisionTree()
     dtree.fit(X_TRAIN, self.labels_train)
     assert dtree.tree is not None
     assert dtree.train_err is not None
Esempio n. 11
0
 def setup(self):
     self.dtree = dt.DecisionTree()
Esempio n. 12
0
 def setup(self):
     self.dtree = dt.DecisionTree()
     self.dtree.fit(X_TRAIN, self.labels_train)
Esempio n. 13
0
 def test_print(self):
     dtree = dt.DecisionTree()
     dtree.fit(X_TRAIN, self.labels_train)
     print(dtree)
Esempio n. 14
0
 def test_classify(self):
     dtree = dt.DecisionTree()
     dtree.fit(X_TRAIN, self.labels_train)
     assert np.all(dtree.classify(X_TRAIN) == self.labels_train)
     assert np.all(dtree.classify(X_TRAIN[5]) == self.labels_train[5])