decision_trees_implementation.py
def ig(X, y, feature_idx, threshold, criterion='gini'):
    """
    Information gain. Function to maximize to get the best split
    """
    X = np.array(X)
    #we split the data according to the threshold
    cond = X[:, feature_idx] < threshold
    y_left = y[cond]
    y_right = y[~cond]
    #length of the origial data and length of each split
    l = len(y)
    ll = len(y_left)
    lr = len(y_right)
    
    if criterion == 'gini':
        return gini(y) - (ll/l)*gini(y_left) - (lr/l)*gini(y_right)
    
    elif criterion == 'entropy':
        return entropy(y) - (ll/l)*entropy(y_left) - (lr/l)*entropy(y_right)

    Information gain. Function to maximize to get the best split
    
Information gain. Function to maximize to get the best split
Information gain . Function to maximize to get the best split
def ig(X, y, feature_idx, threshold, criterion='gini'):
    X = np.array(X)
    cond = X[:, feature_idx] < threshold
    y_left = y[cond]
    y_right = y[~cond]
    l = len(y)
    ll = len(y_left)
    lr = len(y_right)
    if criterion == 'gini':
        return gini(y) - (ll/l)*gini(y_left) - (lr/l)*gini(y_right)
    elif criterion == 'entropy':
        return entropy(y) - (ll/l)*entropy(y_left) - (lr/l)*entropy(y_right)
def ig ( X , y , feature_idx , threshold , criterion = 'gini' ) : X = np . array ( X ) cond = X [ : , feature_idx ] < threshold y_left = y [ cond ] y_right = y [ ~ cond ] l = len ( y ) ll = len ( y_left ) lr = len ( y_right ) if criterion == 'gini' : return gini ( y ) - ( ll / l ) * gini ( y_left ) - ( lr / l ) * gini ( y_right ) elif criterion == 'entropy' : return entropy ( y ) - ( ll / l ) * entropy ( y_left ) - ( lr / l ) * entropy ( y_right )
Information gain.
Information gain .
"""
    Information gain. Function to maximize to get the best split
    """ #we split the data according to the threshold #length of the origial data and length of each split
X
y
feature_idx
threshold
criterion