Esempio n. 1
0
def select_perm(x, y, p=0.05, **kwargs):
    """Select <p significant features using the permutations"""

    n_perm = round(1/p)
    # Classify each features :
    _, _, _, pvalue = classify(x, y, n_perm=n_perm, kind='sf', **kwargs)

    return [k for k in range(0, len(pvalue)) if pvalue[k] < p]
Esempio n. 2
0
def select_bino(x, y, p=0.05, **kwargs):
    """Select <p significant features using the binomial law"""

    allfeat = [k for k in range(0, x.shape[0])]
    # Classify each features :
    da, _, _, _ = classify(x, y, kind='sf', **kwargs)
    # Get significant features :
    signifeat, _ = binofeat(y, da, p)
    # Return list of significant fatures:
    return list(n.array(allfeat)[signifeat])
def signifeat_permutations(x, y, threshold=None, classifier='lda', kern='rbf', n_folds=10, n_jobs=1, n_knn=10,
                           n_perm=100,
                           n_tree=100, cvkind='skfold'):
    "Get significant features based on permutation test"
    if threshold is None:
        threshold = 1 / n_perm

    _, nfeat = x.shape
    signifeat = n.array(range(0, nfeat))
    da, _, _, pvalue = ct.classify(x, y, classifier=classifier, kern=kern, n_folds=n_folds, rep=1,
                                   kind='sf', n_jobs=n_jobs, n_knn=n_knn, n_perm=n_perm, n_tree=n_tree,
                                   cvkind=cvkind)
    upper_features = n.squeeze(pvalue < threshold)
    return signifeat[upper_features], n.squeeze(pvalue), n.squeeze(da)
def classify_combination(x, y, combination, classifier='lda', kern='rbf', n_folds=10, rep=1, n_jobs=1,
                         n_knn=3, n_perm=0, n_tree=100,
                         cvkind='skfold'):
    """Classify each combination and return scores and the best one location."""
    # - Get combination size :
    n_comb = len(combination)

    # - Classify each combination :
    da = n.zeros((1, n_comb))
    for k in range(0, n_comb):
        da[0, k], all_scores, permutation_scores, pvalue = ct.classify(x[:, combination[k]], y, classifier=classifier,
                                                                       kern=kern,
                                                                       n_folds=n_folds, rep=rep, kind='mf',
                                                                       n_jobs=n_jobs,
                                                                       n_knn=n_knn, n_perm=n_perm, n_tree=n_tree,
                                                                       cvkind=cvkind)

    return da, all_scores, permutation_scores, pvalue
def bidimtransform(x, y, ybi, classifier=0, cvkind='skfold', n_folds=10, p=0):
    nbtrans = len(ybi)
    nbepoch, nbfeat = x.shape
    flist = n.array(range(0, nbfeat))
    da = n.zeros((nbtrans, nbfeat))
    signifeat = []
    for i in range(0, nbtrans):
        # First, get index for selected item :
        ylocidx = yloc(y, ybi[i])

        # Select y and x index :
        ynb = y[ylocidx]
        xnb = x[ylocidx, :]

        # Classify each x :
        da[i, :], _, _, _ = ct.classify(xnb, ynb, classifier=classifier, kind='sf', rep=1, cvkind=cvkind,
                                        n_folds=n_folds)

        # Get significant features?
        if p is not 0:
            th = ct.binostat(ynb, p)
            signifeat.extend([flist[100 * da[i, :] >= th]])

    return da, signifeat
Esempio n. 6
0
def select_nbest(x, y, nbest=10, **kwargs):
    """Select nbest features"""

    # Classify each features :
    da, _, _, _ = classify(x, y, kind='sf', **kwargs)
    return list(n.ravel(da.T).argsort()[-nbest:][::-1])