コード例 #1
0
def cfr(X,y,k):
    """
    CFR
    """
    t1=[]
    n_samples, n_features = X.shape
    for i in range(n_features):   #MI
        f = X[:, i]
        t1.append(ees.midd(f, y))
    F=[]
    tt =np.zeros(n_features)

    while len(F)<k:
        if len(F)==0:
            index=t1.index(max(t1))
            F.append(index)
            f_select = X[:, index]
        j_mim = -1000000000000
        for i in xrange(n_features):
            if i not in F:
                fi=X[:, i]
                cmi=ees.cmidd(y,fi ,f_select)
                inter =t1[i]-cmi
                tt[i] +=cmi-inter
                t=tt[i]
                if t> j_mim:
                    j_mim = t
                    idx = i
        F.append(idx)
        f_select = X[:, idx]
    return F
コード例 #2
0
def conditional_entropy(f1, f2):
    """
    This function calculates the conditional entropy, where ce = H(f1) - I(f1;f2)

    Input
    -----
    f1: {numpy array}, shape (n_samples,)
    f2: {numpy array}, shape (n_samples,)

    Output
    ------
    ce: {float}
        ce is conditional entropy of f1 and f2
    """

    ce = ee.entropyd(f1) - ee.midd(f1, f2)
    return ce
コード例 #3
0
def conditional_entropy(f1, f2):
    """
    This function calculates the conditional entropy, where ce = H(f1) - I(f1;f2)

    Input
    -----
    f1: {numpy array}, shape (n_samples,)
    f2: {numpy array}, shape (n_samples,)

    Output
    ------
    ce: {float}
        ce is conditional entropy of f1 and f2
    """

    ce = ee.entropyd(f1) - ee.midd(f1, f2)
    return ce