

def select(self, ensemble, x):
    if ensemble.in_agreement(x):
        return (Ensemble([ensemble.classifiers[0]]), None)
    classifiers = ensemble.classifiers
    [idx] = self.knn.kneighbors(x, return_distance=False)
    (X, y) = (self.Xval[idx], self.yval[idx])
    d = {
        
    }
    scores = [clf.score(X, y) for clf in ensemble.classifiers]
    for (i, scr) in enumerate(scores):
        d[scr] = ((d[scr] + [i]) if (scr in d) else [i])
    best_scores = sorted([k for k in d.iterkeys()], reverse=True)
    if (len(d[best_scores[0]]) == 1):
        i = d[best_scores[0]][0]
        return (Ensemble([classifiers[i]]), None)
    options = None
    for (j, score) in enumerate(best_scores):
        pred = [classifiers[i].predict(x) for i in d[score]]
        pred = np.asarray(pred).flatten()
        bincount = np.bincount(pred)
        if (options != None):
            for i in range(len(bincount)):
                bincount[i] = (bincount[i] if (i in options) else 0)
        imx = np.argmax(bincount)
        votes = np.argwhere((bincount == bincount[imx])).flatten()
        count = len(votes)
        if (count == 1):
            return (Ensemble([classifiers[np.argmax((pred == imx))]]), None)
        elif (options == None):
            options = votes
    return (Ensemble([classifiers[np.argmax(scores)]]), None)

dataset/ETHPy150Open viisar/brew/brew/selection/dynamic/ola.py OLA.select/original