Example #1
0
    for label in range(10):
        index = np.where(y_test == label)[0][0]
        test_images[label] = x_test[index]
    results = np.zeros((2, 10, 28 * 28))
    for mi, model in enumerate(("supervised", "unsupervised")):
        print("Start Autoencoder using {} model".format(model))
        if model == "supervised":
            eforest = RandomForestClassifier(n_estimators=n_trees,
                                             max_depth=None,
                                             n_jobs=-1,
                                             random_state=0)
            eforest.fit(x_train, y_train)
        else:
            eforest = RandomTreesEmbedding(n_estimators=n_trees,
                                           max_depth=None,
                                           n_jobs=-1,
                                           random_state=0)
            eforest.fit(x_train)

        x_encode = eforest.encode(test_images)
        x_decode = eforest.decode(x_encode)
        results[mi] = x_decode
    rheads = ["origin", "supervised", "unsupervised"]
    test_images = test_images.reshape(1, 10, 28, 28)
    results = results.reshape(2, 10, 28, 28)
    fig = plot_mnist(rheads, np.vstack((test_images, results)))
    plt.show()

    import IPython
    IPython.embed()
Example #2
0
        eforest_channels = []
        if model == "supervised":
            for c in range(3):
                eforest = RandomForestClassifier(n_estimators=n_trees,
                                                 max_depth=None,
                                                 n_jobs=-1,
                                                 random_state=0)
                eforest.fit(x_train[:, :, 0], y_train)
                eforest_channels.append(eforest)
        else:
            for c in range(3):
                eforest = RandomTreesEmbedding(n_estimators=n_trees,
                                               max_depth=None,
                                               n_jobs=-1,
                                               random_state=0)
                eforest.fit(x_train[:, :, 0])
                eforest_channels.append(eforest)

        for c in range(3):
            x_encode = eforest.encode(test_images[:, :, c])
            x_decode = eforest.decode(x_encode)
            results[mi, :, :, c] = x_decode
    rheads = ["origin", "supervised", "unsupervised"]
    test_images = test_images.reshape(1, 10, 32, 32, 3).astype(np.uint8)
    results = results.reshape(2, 10, 32, 32, 3).astype(np.uint8)
    fig = plot_cifar10(rheads, np.vstack((test_images, results)))
    plt.show()

    import IPython
    IPython.embed()