Пример #1
0
def run_pcanet_normal(transformer_params,
                      images_train, images_test, y_train, y_test):
    model = PCANet(**transformer_params)
    model.validate_structure()

    t1 = timeit.default_timer()
    model.fit(images_train)
    t2 = timeit.default_timer()
    train_time = t2 - t1

    t1 = timeit.default_timer()
    X_train = model.transform(images_train)
    t2 = timeit.default_timer()
    transform_time = t2 - t1
    X_test = model.transform(images_test)

    y_test, y_pred = run_classifier(X_train, X_test, y_train, y_test)
    accuracy = accuracy_score(y_test, y_pred)

    return model, accuracy, train_time, transform_time
Пример #2
0
train_set, valid_set, test_set = load_mnist()

images_train, y_train = train_set
images_test, y_test = test_set

images_train, y_train = shuffle(images_train, y_train, random_state=0)
images_train, y_train = images_train[:n_train], y_train[:n_train]

images_test, y_test = shuffle(images_test, y_test, random_state=0)
images_test, y_test = images_test[:n_test], y_test[:n_test]

pcanet = PCANet(image_shape=28,
                filter_shape_l1=2,
                step_shape_l1=1,
                n_l1_output=4,
                filter_shape_l2=2,
                step_shape_l2=1,
                n_l2_output=4,
                block_shape=2)
pcanet.validate_structure()

pcanet.fit(images_train)
X_train = pcanet.transform(images_train)
X_test = pcanet.transform(images_test)

model = RandomForestClassifier(n_estimators=100, random_state=1234, n_jobs=-1)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
print("accuracy: " + str(accuracy))
Пример #3
0
images = random.shuffle(images)
print(images)
print(num_examples)
print(images.shape)

pcanet = PCANet(image_shape=(60, 80),
                filter_shape_l1=2,
                step_shape_l1=1,
                n_l1_output=4,
                filter_shape_l2=2,
                step_shape_l2=1,
                n_l2_output=4,
                block_shape=2)

print("has excuted PCANET function")

pcanet.validate_structure()

print("has excuted pcanet.validate_structure")

pcanet.fit(images)

print("has excuted pacnet.fit")

X_train = pcanet.transform(images)

print("has excuted pcanet.transform")

print(X_train)
print(X_train.shape)