Ejemplo n.º 1
0
def _mf(x, Id, grp, self, display, probOccur):
    """cross-validation multifeatures
    """

    # Unpack arguments :
    y = self._y
    cvOut = defCv(y, **self._cvOut).cvr
    clfOut = defClf(y, **self._clfOut)

    # Repetitions loop :
    idxCvOut, da = [], []
    for k, i in enumerate(cvOut):

        predCv, yTestCv = [], []
        for train_index, test_index in i.split(x, y):

            # Get training and testing sets:
            xTrain, xTest, yTrain, yTest = x[train_index, :], x[
                test_index, :], y[train_index], y[test_index]

            # Define the classification object :
            clfObj = classify(yTrain,
                              clf=defClf(yTrain, **self._clfIn),
                              cvtype=defCv(yTrain, **self._cvIn))

            # Get the MF model:
            MFmeth, MFstr = Id2methods(Id,
                                       yTrain,
                                       clfObj,
                                       p=self._p,
                                       display=display,
                                       direction=self._direction,
                                       nbest=self._nbest,
                                       stat=self._stat,
                                       n_perm=self._n_perm)

            # Apply the MF model:
            xCv, idxCvIn, grpIn, MFstrCascade = applyMethods(
                MFmeth, MFstr, xTrain, grp)

            # Select the xTest features:
            xTest = xTest[:, idxCvIn]

            # Classify:
            if xCv.size:
                predCv.extend(clfOut.fit(xCv, yTrain).predict(xTest))
            else:
                predCv.extend(n.array([None] * len(test_index)))

            # Keep info:
            idxCvOut.extend(idxCvIn), yTestCv.extend(yTest)

        # Get the decoding accuracy :
        da.append(100 * sum([
            1 if predCv[k] == yTestCv[k] else 0 for k in range(0, len(predCv))
        ]) / len(predCv))

    prob = occurProba(idxCvOut, list(range(x.shape[1])), kind=probOccur)

    return da, prob, MFstrCascade
Ejemplo n.º 2
0
 def __init__(self, y, Id='0', p=0.05, n_perm=200, stat='bino',
              threshold=None, nbest=10, direction='forward', occurence='i%',
              clfIn={'clf': 'lda'}, clfOut={'clf': 'lda'},
              cvIn={'cvtype': 'skfold', 'n_folds': 10, 'rep': 1},
              cvOut={'cvtype': 'skfold', 'n_folds': 10, 'rep': 10}):
     self._Id = Id
     self._stat = stat
     self._y = np.ravel(y)
     if threshold is not None:
         p = bino_da2p(y, threshold)
     self._p = p
     self._nbest = nbest
     self._n_perm = n_perm
     self._direction = direction
     self._threshold = threshold
     self._occurence = occurence
     self._clfIn = clfIn
     self._clfOut = clfOut
     self._cvIn = cvIn
     self._cvOut = cvOut
     self.setup = {'Id': Id, 'p': p, 'n_perm': n_perm, 'stat': stat,
                   'nbest': nbest, 'threshold': threshold,
                   'direction': direction, 'occurence': occurence,
                   'clfIn': defClf(y, **clfIn).lgStr,
                   'clfOut': defClf(y, **clfOut).lgStr,
                   'cvIn': defCv(y, **cvIn).lgStr,
                   'cvOut': defCv(y, **cvOut).lgStr}
Ejemplo n.º 3
0
def _mf(x, Id, grp, self, display, probOccur):
    """cross-validation multifeatures
    """

    # Unpack arguments :
    y = self._y
    cvOut = defCv(y, **self._cvOut).cvr
    clfOut = defClf(y, **self._clfOut)

    # Repetitions loop :
    idxCvOut, da = [], []
    for k, i in enumerate(cvOut):

        predCv, yTestCv = [], []
        for train_index, test_index in i:

            # Get training and testing sets:
            xTrain, xTest, yTrain, yTest = x[train_index, :], x[
                test_index, :], y[train_index], y[test_index]

            # Define the classification object :
            clfObj = classify(yTrain, clf=defClf(yTrain, **self._clfIn),
                              cvtype=defCv(yTrain, **self._cvIn))

            # Get the MF model:
            MFmeth, MFstr = Id2methods(Id, yTrain, clfObj, p=self._p,
                                       display=display,
                                       direction=self._direction,
                                       nbest=self._nbest,
                                       stat=self._stat, n_perm=self._n_perm)

            # Apply the MF model:
            xCv, idxCvIn, grpIn, MFstrCascade = applyMethods(
                MFmeth, MFstr, xTrain, grp)

            # Select the xTest features:
            xTest = xTest[:, idxCvIn]

            # Classify:
            if xCv.size:
                predCv.extend(clfOut.fit(xCv, yTrain).predict(xTest))
            else:
                predCv.extend(n.array([None] * len(test_index)))

            # Keep info:
            idxCvOut.extend(idxCvIn), yTestCv.extend(yTest)

        # Get the decoding accuracy :
        da.append(100 * sum([1 if predCv[k] == yTestCv[k]
                             else 0 for k in range(0, len(predCv))
                             ]) / len(predCv))

    prob = occurProba(idxCvOut, list(range(x.shape[1])), kind=probOccur)

    return da, prob, MFstrCascade
Ejemplo n.º 4
0
 def __init__(self,
              y,
              Id='0',
              p=0.05,
              n_perm=200,
              stat='bino',
              threshold=None,
              nbest=10,
              direction='forward',
              occurence='i%',
              clfIn={'clf': 'lda'},
              clfOut={'clf': 'lda'},
              cvIn={
                  'cvtype': 'skfold',
                  'n_folds': 10,
                  'rep': 1
              },
              cvOut={
                  'cvtype': 'skfold',
                  'n_folds': 10,
                  'rep': 10
              }):
     self._Id = Id
     self._stat = stat
     self._y = np.ravel(y)
     if threshold is not None:
         p = bino_da2p(y, threshold)
     self._p = p
     self._nbest = nbest
     self._n_perm = n_perm
     self._direction = direction
     self._threshold = threshold
     self._occurence = occurence
     self._clfIn = clfIn
     self._clfOut = clfOut
     self._cvIn = cvIn
     self._cvOut = cvOut
     self.setup = {
         'Id': Id,
         'p': p,
         'n_perm': n_perm,
         'stat': stat,
         'nbest': nbest,
         'threshold': threshold,
         'direction': direction,
         'occurence': occurence,
         'clfIn': defClf(y, **clfIn).lgStr,
         'clfOut': defClf(y, **clfOut).lgStr,
         'cvIn': defCv(y, **cvIn).lgStr,
         'cvOut': defCv(y, **cvOut).lgStr
     }