예제 #1
0
    mode = args.mode[0]

    return args, mode


if __name__ == '__main__':
    args, mode = parse_args() # get argument from the command line

    # load the data
    train_set, train_labels, test_set, test_labels = load_data(train_set_path=args.train_set_path,
                                                                       train_labels_path=args.train_labels_path,
                                                                       test_set_path=args.test_set_path,
                                                                       test_labels_path=args.test_labels_path)
    if mode == 'feature_sel':
        selected_features = feature_selection(train_set, train_labels)
        print_features(selected_features)
    elif mode == 'knn':
        predictions = knn(train_set, train_labels, test_set, args.k)
        print_predictions(predictions)
    elif mode == 'alt':
        predictions = alternative_classifier(train_set, train_labels, test_set)
        print_predictions(predictions)
    elif mode == 'knn_3d':
        predictions = knn_three_features(train_set, train_labels, test_set, args.k)
        print_predictions(predictions)
    elif mode == 'knn_pca':
        prediction = knn_pca(train_set, train_labels, test_set, args.k)
        print_predictions(prediction)
    else:
        raise Exception('Unrecognised mode: {}. Possible modes are: {}'.format(mode, MODES))
예제 #2
0
    return args, task


if __name__ == '__main__':
    args, task = parse_args()  # get argument from the command line

    # load the data
    train_set, train_labels, test_set, test_labels = load_data(
        train_set_path=args.train_set_path,
        train_labels_path=args.train_labels_path,
        test_set_path=args.test_set_path,
        test_labels_path=args.test_labels_path)
    if task == 'feature_sel':
        selected_features = feature_selection(train_set, train_labels, args.f)
        print_features(np.array(selected_features) - 1)
    elif task == 'knn':
        predictions = knn(train_set, train_labels, test_set, args.k)
        print_predictions(predictions)
    elif task == 'alt':
        predictions = alternative_classifier(train_set, train_labels, test_set)
        print_predictions(predictions)
    elif task == 'knn_3d':
        predictions = knn_three_features(train_set, train_labels, test_set,
                                         args.k)
        print_predictions(predictions)
    elif task == 'knn_pca':
        predictions = knn_pca(train_set, train_labels, test_set, args.k)
        print_predictions(predictions)
    elif task == 'feature_plots':
        subplots(train_set1, n_features)