コード例 #1
0
def pre_featsel (X, y, method, thr=95, dist_function=None, thr_method='robust'):
    '''
    INPUT
    X             : data ([n_samps x n_feats] matrix)
    y             : class labels
    method        : distance measure: 'pearson', 'bhattacharyya', 'welcht', ''
                    if method == '', will use dist_function
    thr           : percentile distance threshold
    dist_function : 
    thr_method    : method for thresholding: 'none', 'robust', 'ranking'

    OUTPUT
    m          : distance measure (thresholded or not)
    '''

    #pre feature selection, measuring distances
    #Pearson correlation
    if method == 'pearson':
        au.log.info ('Calculating Pearson correlation')
        m = np.abs(pearson_correlation (X, y))

    #Bhattacharyya distance
    elif method == 'bhattacharyya':
        au.log.info ('Calculating Bhattacharyya distance')
        m = bhattacharyya_dist (X, y)

    #Welch's t-test
    elif method == 'welcht':
        au.log.info ("Calculating Welch's t-test")
        m = welch_ttest (X, y)

    elif method == '':
        au.log.info ("Calculating distance between data and class labels")
        #http://docs.scipy.org/doc/scipy/reference/spatial.distance.html
        m = distance_computation(X, y, dist_function)

    #if all distance values are 0
    if not m.any():
        au.log.info("No differences between groups have been found. Are you sure you want to continue?")
        return m

    #threshold data
    if thr_method != 'none':
        if thr_method == 'robust':
            mt = au.robust_range_threshold (m, thr)
        elif thr_method == 'percentile':
            mt = au.percentile_threshold (m, thr)
        elif thr_method == 'rank':
            mt = au.rank_threshold (m, thr)

        return mt

    return m
コード例 #2
0
def apply_distance_threshold (distances, thr, method='robust'):
    if   method == 'robust':     return au.robust_range_threshold (distances, thr)
    elif method == 'rank':       return au.rank_threshold         (distances, thr)
    elif method == 'percentile': return au.percentile_threshold   (distances, thr)