def separation(X,y,samples=False):
    """ return the sum of the between-class squared distance"""
    # pdb.set_trace()
    num_classes = len(np.unique(y))
    total_dist = (X.max()-X.min())**2
    if samples:
        # return intra-class distance for each sample
        separation = np.zeros(y.shape)
        for label in np.unique(y):
            for outsider in np.unique(y[y!=label]):
                separation[y==label] += (X[y==label] - np.mean(X[y==outsider])) ** 2

        #normalize between 0 and 1
        print('separation:',separation)
        print('num_classes:',num_classes)
        print('total_dist:',total_dist)
        separation = separation#/separation.max()

        print('separation after normalization:',separation)

    else:
        # return aggregate score
        separation = 0
        for i,label in enumerate(np.unique(y)):
            for outsider in np.unique(y[y!=label]):
                separation += np.sum((X[y==label] - np.mean(X[y==outsider])) ** 2)/len(y[y==label])
        separation = separation/len(np.unique(y))

    return separation
def separation ( X , y , samples = False ) : num_classes = len ( np . unique ( y ) ) total_dist = ( X . max ( ) - X . min ( ) ) ** 2 if samples : separation = np . zeros ( y . shape ) for label in np . unique ( y ) : for outsider in np . unique ( y [ y != label ] ) : separation [ y == label ] += ( X [ y == label ] - np . mean ( X [ y == outsider ] ) ) ** 2 print ( 'separation:' , separation ) print ( 'num_classes:' , num_classes ) print ( 'total_dist:' , total_dist ) separation = separation print ( 'separation after normalization:' , separation ) else : separation = 0 for i , label in enumerate ( np . unique ( y ) ) : for outsider in np . unique ( y [ y != label ] ) : separation += np . sum ( ( X [ y == label ] - np . mean ( X [ y == outsider ] ) ) ** 2 ) / len ( y [ y == label ] ) separation = separation / len ( np . unique ( y ) ) return separation
return the sum of the between-class squared distance