Пример #1
0
def main():
    classifier = svm.SVC()
    transformed_train_data = [
        create_feature_vector(coordinates) for coordinates in train_data
    ]

    classifier.fit(transformed_train_data, train_labels)

    test_data, test_labels = apa.read_data_files(train_files)
    transformed_test_data = [
        create_feature_vector(coordinates) for coordinates in test_data
    ]
    predicted = classifier.predict(transformed_test_data)

    conf_mat = np.zeros((10, 10))

    success, error = 0, 0
    for test_label, predicted_label in zip(test_labels, predicted):
        conf_mat[test_label, predicted_label] += 1
        if test_label == predicted_label:
            success += 1
        else:
            error += 1

    precision = success / float(success + error) * 100

    print("precision: %s " % precision)
    print_conf_mat(conf_mat)
Пример #2
0
def main():
    classifier = svm.SVC()
    transformed_train_data = [create_feature_vector(coordinates) for coordinates in train_data]

    classifier.fit(transformed_train_data, train_labels)

    test_data, test_labels = apa.read_data_files(train_files)
    transformed_test_data = [create_feature_vector(coordinates) for coordinates in test_data]
    predicted = classifier.predict(transformed_test_data)

    conf_mat = np.zeros((10, 10))

    success, error = 0, 0
    for test_label, predicted_label in zip(test_labels, predicted):
        conf_mat[test_label, predicted_label] += 1
        if test_label == predicted_label:
            success += 1
        else:
            error += 1

    precision = success / float(success + error) * 100

    print("precision: %s " % precision)
    print_conf_mat(conf_mat)
Пример #3
0
test_nums = ['15', '19', '20']
apa_train_dirs = ["%s/apa%s" % (apa_data_path, i) for i in train_nums]
apa_test_dirs = ["%s/apa%s" % (apa_data_path, i) for i in test_nums]


def get_apa_files(apa_dirs):
    files = []
    for apa_dir in apa_dirs:
        files += map(lambda s: os.path.join(apa_dir, s), os.listdir(apa_dir))

    return files

train_files = get_apa_files(apa_train_dirs)
test_files = get_apa_files(apa_test_dirs)

train_data, train_labels = apa.read_data_files(train_files)


def create_feature_vector(coordinates):
    X, Y = [], []
    for x, y in coordinates:
        X.append(x)
        Y.append(y)

    total_distance = 0
    for pair in zip(coordinates[0:len(coordinates)-2], coordinates[1::len(coordinates)-1]):
        a, b = pair
        distance = np.linalg.norm(a-b)
        total_distance += distance

    var_x = np.var(X)
Пример #4
0
apa_train_dirs = ["%s/apa%s" % (apa_data_path, i) for i in train_nums]
apa_test_dirs = ["%s/apa%s" % (apa_data_path, i) for i in test_nums]


def get_apa_files(apa_dirs):
    files = []
    for apa_dir in apa_dirs:
        files += map(lambda s: os.path.join(apa_dir, s), os.listdir(apa_dir))

    return files


train_files = get_apa_files(apa_train_dirs)
test_files = get_apa_files(apa_test_dirs)

train_data, train_labels = apa.read_data_files(train_files)


def create_feature_vector(coordinates):
    X, Y = [], []
    for x, y in coordinates:
        X.append(x)
        Y.append(y)

    total_distance = 0
    for pair in zip(coordinates[0:len(coordinates) - 2],
                    coordinates[1::len(coordinates) - 1]):
        a, b = pair
        distance = np.linalg.norm(a - b)
        total_distance += distance