예제 #1
0
파일: combination.py 프로젝트: HendryLi/ml
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
예제 #2
0
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
예제 #3
0
파일: knn.py 프로젝트: rafaelbarreto87/ml
    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]
예제 #4
0
파일: knn.py 프로젝트: AymanNabih/ml
    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]