예제 #1
0
def main():
    real_data = neigh.read_trainer('wdbc.data')
    synth_data = neigh.make_synth()
    n = 10
    classifier = neigh.NNclassifier
    real_perf = neigh.n_validator(real_data, n, classifier)
    synth_perf = neigh.n_validator(synth_data, n, classifier)
    print()
    print('The model\'s ' + str(n) + '-fold validated performance with real data is ' + str(real_perf)[:5] + '.')
    print('The model\'s ' + str(n) + '-fold validated performance with synthetic data is ' + str(synth_perf) + '.')
    return
예제 #2
0
def main():
    real_data = neigh.read_trainer('wdbc.data')
    synth_data = neigh.make_synth()
    n = 10
    classifier = neigh.KNNclassifier
    norm = [neigh.np.inf, 1]   # Maximum norm and l-1 norm
    best_real_k = 1
    best_real_perf = 0
    best_synth_k = 1
    best_synth_perf = 0
    for m in norm:
        for k in range(1, 16, 2):
            real_perf = neigh.n_validator(real_data, n, classifier, k, m)
            if real_perf > best_real_perf:
                best_real_perf = real_perf
                best_real_k = k
            synth_perf = neigh.n_validator(synth_data, n, classifier, k, m)
            if synth_perf > best_synth_perf:
                best_synth_perf = synth_perf
                best_synth_k = k
            print()
            print('The '
                  + str(k) + '-Nearest Neighbor\'s '
                  + str(n) + '-fold validated performance with real data using the '
                  + str(m) + '-norm is '
                  + str(real_perf)[:5] + '.')
            print('The '
                  + str(k) + '-Nearest Neighbor\'s '
                  + str(n) + '-fold validated performance with synthetic data using the '
                  + str(m) + '-norm is '
                  + str(synth_perf) + '.')
        print()
        print('The best k for real data with the '
              + str(m) + '-norm was '
              + str(best_real_k) + ' with a performance of '
              + str(best_real_perf)[:5] + '.')
        print('The best k for synthetic data with the '
              + str(m) + '-norm was '
              + str(best_synth_k) + ' with a performance of '
              + str(best_synth_perf) + '.')
    return