예제 #1
0
        ax.scatter(Z[:,0], Z[:,1])
        plt.ylabel('z2')
        plt.xlabel('z1')
        plt.title('MDS')
        for i in range(n):
            ax.annotate(animals[i], (Z[i,0], Z[i,1]))
        utils.savefig('MDS_animals.png')

    elif question == '4.1':
        dataset = load_dataset('animals.pkl')
        X = dataset['X'].astype(float)
        animals = dataset['animals']
        n,d = X.shape

        for n_neighbours in [2,3]:
        #for n_neighbours in range(n):
            model = ISOMAP(n_components=2, 
                           n_neighbours=n_neighbours) # TODO: finish implementing this class
            Z = model.compress(X)

            fig, ax = plt.subplots()
            ax.scatter(Z[:,0], Z[:,1])
            plt.ylabel('z2')
            plt.xlabel('z1')
            plt.title('ISOMAP with NN=%d' % n_neighbours)
            for i in range(n):
                ax.annotate(animals[i], (Z[i,0], Z[i,1]))
            utils.savefig('ISOMAP%d_animals.png' % n_neighbours)

    else:
        print("Unknown question: %s" % question)
예제 #2
0
        fig, ax = plt.subplots()
        ax.scatter(Z[:, 0], Z[:, 1])
        plt.ylabel('z2')
        plt.xlabel('z1')
        plt.title('MDS')
        for i in range(n):
            ax.annotate(animals[i], (Z[i, 0], Z[i, 1]))
        utils.savefig('MDS_animals.png')

    elif question == '4.1':
        dataset = load_dataset('animals.pkl')
        X = dataset['X'].astype(float)
        animals = dataset['animals']
        n, d = X.shape

        for n_neighbours in [2, 3]:
            model = ISOMAP(n_components=2, n_neighbours=n_neighbours)
            Z = model.compress(X)

            fig, ax = plt.subplots()
            ax.scatter(Z[:, 0], Z[:, 1])
            plt.ylabel('z2')
            plt.xlabel('z1')
            plt.title('ISOMAP with NN=%d' % n_neighbours)
            for i in range(n):
                ax.annotate(animals[i], (Z[i, 0], Z[i, 1]))
            utils.savefig('ISOMAP%d_animals.png' % n_neighbours)

    else:
        print("Unknown question: %s" % question)
예제 #3
0
        X = data.values
        names = X[:,0]
        # get rid of country names
        X = X[:,1:]
        X = np.array(X).astype(np.float32)
        X[X<=0] = 1.
        X[np.isnan(X)] = 1.
        X[np.isinf(X)] = 1.
        X = np.log(X)
        #X = X / X.max()
        n,d = X.shape
        print("n =", n)
        print("d =", d)

        for n_neighbours in [2,3]:
            model = ISOMAP(n_components=2, n_neighbours=n_neighbours)
            Z = model.compress(X)
            fig, ax = plt.subplots()
            ax.scatter(Z[:,0], Z[:,1])
            plt.ylabel('z2')
            plt.xlabel('z1')
            plt.title('ISOMAP with NN=%d' % n_neighbours)
            for i in range(n):
                ax.annotate(names[i], (Z[i,0], Z[i,1]))
            utils.savefig('ISOMAP%d_animals.png' % n_neighbours)
        #pca = PCA(n_components = 2)
        #pca.fit(X)
        #pcaTransform = pca.transform(X)
        #f1 = pcaTransform[:, 0]
        #f2 = pcaTransform[:, 1] #np.random.choice(d, size=2, replace=False)
        #print(pca.singular_values_)