Пример #1
0
    def branching(tree, left, node_id, criterion, parent):
        value = tree.value[node_id]
        if tree.n_outputs == 1:
            value = value[0, :]
        if tree.children_left[
                node_id] == _tree.TREE_LEAF and tree.children_right[
                    node_id] == _tree.TREE_LEAF:
            #temp = np.where(value!=0)[0].tolist()
            temp = np.where(value == max(value))[0].tolist()
            temp = ['__' + str(i + 1) for i in temp]
            more = '---> more' if len(temp) > 1 else ''
            samples = tree.n_node_samples[node_id]
            if delete_more:
                if len(temp) > 1:
                    if left:
                        if tree.children_right[parent] != _tree.TREE_LEAF:
                            tree.children_left[parent] = _tree.TREE_LEAF
                        else:
                            r = tree.value[
                                tree.children_right[parent]][0].tolist()
                            l = value.tolist()
                            tree.value[node_id][0] = np.array(
                                [i + j for i, j in zip(l, r)])

                    else:
                        if tree.children_left[parent] != _tree.TREE_LEAF:
                            tree.children_right[parent] = _tree.TREE_LEAF
                        else:
                            l = tree.value[
                                tree.children_left[parent]][0].tolist()
                            r = value.tolist()
                            tree.value[node_id][0] = np.array(
                                [i + j for i, j in zip(l, r)])

            return "%s  # samples = %s #  %s"  \
                % (temp,
                   samples,
                   more)
        else:
            if feature_names is not None:
                feature = feature_names[tree.feature[node_id]]
            else:
                feature = "X[%s]" % tree.feature[node_id]

            #add condition at node to current branch
            return "%s <= %.4f samples = %s" \
                   % (feature,
                      tree.threshold[node_id],
                      tree.n_node_samples[node_id])
Пример #2
0
 def branching(tree, left, node_id, criterion, parent):
     value = tree.value[node_id]
     if tree.n_outputs == 1:
         value = value[0, :]
     if tree.children_left[node_id] == _tree.TREE_LEAF and tree.children_right[node_id] == _tree.TREE_LEAF:
         #temp = np.where(value!=0)[0].tolist()
         temp = np.where(value==max(value))[0].tolist()
         temp = ['__'+str(i+1) for i in temp]
         more = '---> more' if len(temp)>1 else ''
         samples = tree.n_node_samples[node_id]
         if delete_more:
             if len(temp) > 1:
                 if left:
                     if tree.children_right[parent] != _tree.TREE_LEAF:
                         tree.children_left[parent] = _tree.TREE_LEAF
                     else:
                         r = tree.value[tree.children_right[parent]][0].tolist()
                         l = value.tolist()
                         tree.value[node_id][0] = np.array([i+j for i,j in zip(l,r)])
                         
                 else:
                     if tree.children_left[parent] != _tree.TREE_LEAF:
                         tree.children_right[parent] = _tree.TREE_LEAF
                     else:
                         l = tree.value[tree.children_left[parent]][0].tolist()
                         r = value.tolist()
                         tree.value[node_id][0] = np.array([i+j for i,j in zip(l,r)])
                         
         return "%s  # samples = %s #  %s"  \
             % (temp,
                samples,
                more)
     else:
         if feature_names is not None:
             feature = feature_names[tree.feature[node_id]]
         else:
             feature = "X[%s]" % tree.feature[node_id]
         
         #add condition at node to current branch
         return "%s <= %.4f samples = %s" \
                % (feature,
                   tree.threshold[node_id],
                   tree.n_node_samples[node_id])
Пример #3
0
 def collect(clus,t,l,n_id,c,p):
     val = t.value[n_id]
     if t.n_outputs == 1:
         val = val[0,:]
     
     test_for_exclusives = np.equal(val,np.array([0.0]*len(val)))
     if False in test_for_exclusives:
         clu = np.where(val==max(val))[0].tolist()
         for i in clu:
             if i not in clus: clus.append(i)
     return clus
Пример #4
0
        def collect(clus, t, l, n_id, c, p):
            val = t.value[n_id]
            if t.n_outputs == 1:
                val = val[0, :]

            test_for_exclusives = np.equal(val, np.array([0.0] * len(val)))
            if False in test_for_exclusives:
                clu = np.where(val == max(val))[0].tolist()
                for i in clu:
                    if i not in clus: clus.append(i)
            return clus