ape_tabular_experiments.py
def decision_tree_function(clf, instance):
    """
    Args: clf: Trained decision tree model
          instance: Target instance to explain
    Return: the set of features employed by the decision tree model
    """
    feature = clf.tree_.feature
    node_indicator = clf.decision_path(instance)
    leaf_id = clf.apply(instance)

    sample_id = 0
    node_index = node_indicator.indices[node_indicator.indptr[sample_id]:
                                        node_indicator.indptr[sample_id + 1]]
    
    #print('Rules used to predict sample {id}:\n'.format(id=sample_id))
    feature_employed = []
    for node_id in node_index:
        # continue to the next node if it is a leaf node
        if leaf_id[sample_id] == node_id:
            continue
        feature_employed.append(feature[node_id])
    return set(feature_employed)

    Args: clf: Trained decision tree model
          instance: Target instance to explain
    Return: the set of features employed by the decision tree model
    
Trained decision tree model
instance: Target instance to explain
Return: the set of features employed by the decision tree model
Trained decision tree model instance : Target instance to explain Return : the set of features employed by the decision tree model
def decision_tree_function(clf, instance):
    feature = clf.tree_.feature
    node_indicator = clf.decision_path(instance)
    leaf_id = clf.apply(instance)
    sample_id = 0
    node_index = node_indicator.indices[node_indicator.indptr[sample_id]:
                                        node_indicator.indptr[sample_id + 1]]
    feature_employed = []
    for node_id in node_index:
        if leaf_id[sample_id] == node_id:
            continue
        feature_employed.append(feature[node_id])
    return set(feature_employed)
def decision_tree_function ( clf , instance ) : feature = clf . tree_ . feature node_indicator = clf . decision_path ( instance ) leaf_id = clf . apply ( instance ) sample_id = 0 node_index = node_indicator . indices [ node_indicator . indptr [ sample_id ] : node_indicator . indptr [ sample_id + 1 ] ] feature_employed = [ ] for node_id in node_index : if leaf_id [ sample_id ] == node_id : continue feature_employed . append ( feature [ node_id ] ) return set ( feature_employed )
Args: clf: Trained decision tree model
instance: Target instance to explain
Return: the set of features employed by the decision tree model
Args : clf : Trained decision tree model instance : Target instance to explain Return : the set of features employed by the decision tree model
"""
    Args: clf: Trained decision tree model
          instance: Target instance to explain
    Return: the set of features employed by the decision tree model
    """ #print('Rules used to predict sample {id}:\n'.format(id=sample_id)) # continue to the next node if it is a leaf node
clf
instance