BetaCodeShareBeta

by Code Solutions Project

Simple solutions for common problems

External library: 2.2.1 Version used: 2.2.1
Description:Create a votation with the predictions of different classifiers and their weights for calculate the ponderate vote.
Python
MagRag
def weighted_vote(predictions, weights, one_hot):
        y_complete = np.sum(
            [
                self.one_hot.transform(p.reshape(-1, 1)) * wi
                for p, wi in zip(predictions, weights)
            ],
            0,
        )
        y_zeros = np.zeros(y_complete.shape)
        y_zeros[np.arange(y_complete.shape[0]), y_complete.argmax(1)] = 1

        return one_hot.inverse_transform(y_zeros).flatten()

Input example

predictions -> 2d array (instances, classes)
weights -> 1d array (voters)
one_hot -> A one hot encoder previous calculated with the classes

Output example

1d array (instances) with the votes
View version's history
×Oh snap! Something wrong