def dssgRunCV(binaryClassifierObj,
              dsetBinary,
              nFolds=5):
    """
    raise TooSkewedLabelsException when CV can't be done

    """

    #--- Get staritified folds
    y = map(lambda x: 1 if x[1] == 'pos' else 0, dsetBinary)

    #- exception: if there is num(y==1)< 2 or num(y==0)<2, can't do CV.
    ySum = sum(y)
    if ySum < 2 or len(y) - ySum < 2:
        raise TooSkewedLabelsException()

    folds = StratifiedKFold(y, nFolds)

    #--- Compute accuracy
    accList = []
    precList = []
    recallList = []
    f1List = []
    allTruey = [x[1] for x in dsetBinary]
    allPredy = [float('nan')] * len(dsetBinary)
    for trainIdx, testIdx in folds:
        train = [dsetBinary[i] for i in trainIdx]
        test = [dsetBinary[i] for i in testIdx]

        binaryClassifier = copy.deepcopy(binaryClassifierObj)
        binaryClassifier.train(train)

        #-- compute accuracy (or other stats?)
        predy = []
        for x in test:
            predScore = binaryClassifier.predictScore(x[0])
            predy.append('pos' if predScore['pos'] >= 0 else 'neg')

        truey = [x[1] for x in test]
        acc = metrics.accuracy_score(truey, predy)
        accList.append(acc)

        #-
        for i in range(len(test)):
            allPredy[testIdx[i]] = predy[i]

    #- compute prec, recall, f1
    prec = metrics.precision_score(allTruey, allPredy, pos_label='pos')
    recall = metrics.recall_score(allTruey, allPredy, pos_label='pos')
    f1 = metrics.f1_score(allTruey, allPredy, pos_label='pos')
    nTP = sum(
        [allTruey[i] == 'pos' and allPredy[i] == 'pos' for i in range(len(allTruey))])
    nFP = sum(
        [allTruey[i] == 'neg' and allPredy[i] == 'pos' for i in range(len(allTruey))])
    nTN = sum(
        [allTruey[i] == 'neg' and allPredy[i] == 'neg' for i in range(len(allTruey))])
    nFN = sum(
        [allTruey[i] == 'pos' and allPredy[i] == 'neg' for i in range(len(allTruey))])

    resDic = {}
    resDic['nFolds'] = nFolds
    me = np.mean(accList)
    resDic['mean of accuracy'] = me
    stderr = stats.sem(accList)
    resDic['standard error of accuracy'] = stderr
    alpha = 0.05
    # failure rate
    dev = stderr * stats.t.ppf(1 - alpha / 2, len(accList) - 1)
    resDic['95% confidence interval'] = (me - dev, me + dev)
    resDic['precision'] = prec
    resDic['recall'] = recall
    resDic['f1'] = f1
    resDic['nTP'] = nTP
    resDic['nFP'] = nFP
    resDic['nTN'] = nTN
    resDic['nFN'] = nFN

    return resDic
dataset/ETHPy150Open dssg/ushine-learning/dssg/classifier.py/dssgRunCV/original