Esempio n. 1
0
def test_invalid_reason_can_be_setted_and_getted():
    """ Test that invalid reasons can be set and accessed on a split instance """
    split = CHAID.Split("a", None, None, 1, 0)
    reason = CHAID.InvalidSplitReason.ALPHA_MERGE
    split.invalid_reason = reason

    assert split.invalid_reason == reason, 'Splits should be able to store invalid reasons'
Esempio n. 2
0
 def setUp(self):
     invalid_split = CHAID.Split(None, None, 0, 1, 0)
     self.tree = CHAID.Tree.from_numpy(np.array([[1]]), np.array([1]))
     self.tree._tree_store = [
         CHAID.Node(node_id=0,
                    split=CHAID.Split('a', [[1], [2]], 1, 0.2, 2)),
         CHAID.Node(node_id=1, split=invalid_split, choices=[1], parent=0),
         CHAID.Node(node_id=2,
                    split=CHAID.Split('c', [[3]], 1, 0.2, 2),
                    choices=[2],
                    parent=0)
     ]
     self.last_node = CHAID.Node(node_id=3,
                                 split=invalid_split,
                                 choices=[3],
                                 parent=2)
     self.tree._tree_store.append(self.last_node)
Esempio n. 3
0
def test_node_should_have_a_score():
    """
    Tests that node uses the split score and is called 'score'
    """
    data = np.array([1.3, 23.0, 3.0, 3.0, 12.4])
    continuous_dp = CHAID.ContinuousColumn(data)
    split = CHAID.Split("a", [], 2, 3, 4)
    node = CHAID.Node(dep_v=continuous_dp, split=split)
    assert node.score == 2
def test_column_name_mappings():
    """ Test column name mappings are applied correctly """
    column_names = ["a", "b", "c"]
    cols = range(0, len(column_names))
    splits = [CHAID.Split(col, None, None, 1, 0) for col in cols]

    for split in splits:
        assert split.column == str(split.column_id), 'Names should be column id when mapping not applied'
        split.name_columns(column_names)
        assert split.column == column_names[split.column_id], 'Names should correctly map to column name when mapping is applied'
Esempio n. 5
0
def test_invalid_split():
    """ Test properties when split invalid """
    split = CHAID.Split(None, None, None, 1, 0)
    assert split.invalid_reason == None
    assert split.column == None