Ejemplo n.º 1
0
def svm_baseline():
    img_images, img_labels, tst_images, tst_labels = main.load_mnist()
    training_images, training_labels = util.subSample(img_images, img_labels,
                                                      50000)
    training_data = (training_images, training_labels)
    test_data = (tst_images, tst_labels)
    print(training_data[0].shape)
    print(training_data[1].shape)
    print(test_data[0].shape)
    print(test_data[1].shape)
    # train
    clf = svm.SVC()
    clf.fit(training_data[0], training_data[1])
    # test
    predictions = [int(a) for a in clf.predict(test_data[0])]
    num_correct = sum(int(a == y) for a, y in zip(predictions, test_data[1]))
    print("Baseline classifier using an SVM.")
    print("%s of %s values correct." % (num_correct, len(test_data[1])))
Ejemplo n.º 2
0
from main import training
from main import test
from main import load_mnist

img_images, img_labels, tst_images, tst_labels = load_mnist()
print(img_images.shape)
clf = training(img_images, img_labels, 500)
test_size = 100
num_correct = test(clf, tst_images, tst_labels, test_size)
print ("Baseline classifier using an SVM.")
print ("%s of %s values correct." % (num_correct, test_size))

Ejemplo n.º 3
0
    parser.add_argument('--max_params', default=0, type=int)

    parser.add_argument('chromosome', help="Chromosme")
    args = parser.parse_args()
    set_args(args)
    print(args)

    if not os.path.exists(args.save_dir):
        os.makedirs(args.save_dir)

    if not os.path.exists(args.cache_dir):
        os.makedirs(args.cache_dir)

    # load data
    if args.dataset == 'mnist':
        (x_train, y_train), (x_test, y_test) = load_mnist()
        inshape = [28, 1, 1, 10]
    elif args.dataset == 'fmnist' or args.dataset == 'fashion_mnist':
        (x_train, y_train), (x_test, y_test) = load_fmnist()
        inshape = [28, 1, 1, 10]
    elif args.dataset == 'cifar10':
        from keras.datasets import cifar10
        (x_train, y_train), (x_test, y_test) = load_cifar10()
        inshape = [32, 3, 1, 10]
    elif args.dataset == 'cifar100':
        from keras.datasets import cifar100
        (x_train, y_train), (x_test, y_test) = load_cifar100()
        inshape = [32, 3, 1, 100]
    elif args.dataset == 'svhn':
        (x_train, y_train), (x_test, y_test) = load_svhn()
        inshape = [32, 3, 1, 10]
Ejemplo n.º 4
0
# -*- coding: utf-8 -*-

from main import load_mnist
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from KernelizedPerceptron import MyKP



if __name__ == '__main__':
    images, labels = load_mnist('data/fashion')
    x_test, y_test = load_mnist('data/fashion', kind='t10k')
    x_train, x_validation, y_train, y_validation =\
        train_test_split(images, labels, test_size=0.2)
    degree = [2, 3, 4]
    for i in degree:
        MyKP(x_train, y_train, x_validation,
             y_validation, x_test, y_test, i)