def majority_vote_classifier(classifiers, same_feature_space=True): assert len(classifiers) % 2 != 0 if same_feature_space: classifier = lambda x: mode([c(x) for c in classifiers])[0][0] else: classifier = lambda x: mode([classifiers[i](x[i]) \ for i in xrange(len(classifiers))])[0][0] return classifier
def classifier(x): x = np.asarray(x).ravel() assert len(x) == d, "Incorrect dimensionality. The input data must " "be %d-dimensional." % d dists = cdist([x], data, metric=dist_metric, **dist_kwargs).squeeze() sorted_dists_idx = dists.argsort()[0:k] weights = 1 / (dists[sorted_dists_idx] ** 2) if weighted else None return mode(labels[sorted_dists_idx], weights)[0][0]
def classifier(x): x = np.asarray(x).ravel() assert len(x) == d, "Incorrect dimensionality. The input data must " \ "be %d-dimensional." % d dists = cdist([x], data, metric=dist_metric, **dist_kwargs).squeeze() sorted_dists_idx = dists.argsort()[0:k] weights = 1 / (dists[sorted_dists_idx]**2) if weighted else None return mode(labels[sorted_dists_idx], weights)[0][0]