def test_display_dimensions(self):
        data_dir = 'datasets/'
        data_set = 'glass/glass.data'
        file = os.path.join(data_dir, data_set)

        print('Displaying data set {%s} in the Rn' % file)

        glass = Retriever(file, delimiter=',')

        # Glass has the samples' ids in the first column.
        glass.split_column(0)
        # Additionally, its last column represents the target feature.
        glass.split_target()

        data, c = glass.retrieve()
        reduced_data = algorithms.Isomap(data, e=20).run()

        d = Displayer(title=data_set)

        # Scatter all dimensions (3-by-3), using as many graphs as necessary.
        for begin in range(0, glass.features_count, 3):
            end = min(glass.features_count, begin + 3)
            d.load(data[:, begin:end],
                   color=c,
                   title='Dimensions: d e [%i, %i]' % (begin + 1, end))

        d \
            .load('Reduced glass data-set', reduced_data, c) \
            .show()
示例#2
0
    def test_random_matrix(self):
        data = np.trunc(5 + 10 * np.random.rand(10, 3))

        neighbors = 2
        epsilon = 5.
        to_dimension = 2

        d = Displayer(title="Isomap algorithms comparison") \
            .load(title="Canonical data set.", data=data)

        start = time()
        result = manifold.Isomap(neighbors, to_dimension).fit_transform(data)
        elapsed = time() - start

        d.load(title="SKLearn's Isomap with %i neighbors, taking %.1fs." % (neighbors, elapsed),
               data=result)

        start = time()
        result = algorithms.Isomap(nearest_method='e', e=epsilon, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        d.load(title="My E-Isomap with epsilon %i, taking %.1fs." % (epsilon, elapsed),
               data=result)

        start = time()
        result = algorithms.Isomap(k=neighbors, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        d.load(title="My K-Isomap with %i neighbors, taking %.1fs." % (neighbors, elapsed),
               data=result)

        d.show()
示例#3
0
    def test_canonical_data(self):
        data = np.array([
            [0, 0, 0],
            [1, 0, 0],
            [1, 1, 0],
            [1, 1, 1],
        ])

        c = np.array([0, 0, 1, 1])

        neighbors = 2
        epsilon = 1.5
        to_dimension = 2

        d = Displayer(title="Isomap algorithms comparison") \
            .load(title="Canonical data set.", data=data, color=c)

        start = time()
        result = manifold.Isomap(neighbors, to_dimension).fit_transform(data)
        elapsed = time() - start

        d.load(title="SKLearn's Isomap with %i neighbors, taking %.1fs." % (neighbors, elapsed),
               data=result,
               color=c)

        start = time()
        result = algorithms.Isomap(nearest_method='e', e=epsilon, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        d.load(title="My E-Isomap with epsilon %i, taking %.1fs." % (epsilon, elapsed),
               data=result,
               color=c)

        start = time()
        result = algorithms.Isomap(k=neighbors, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        d.load(title="My K-Isomap with %i neighbors, taking %.1fs." % (neighbors, elapsed),
               data=result,
               color=c)

        d.show()
示例#4
0
    def test_swiss_roll(self):
        samples = 1000
        neighbors = 10
        epsilon = 5
        to_dimension = 2

        data, c = datasets.make_swiss_roll(n_samples=samples, random_state=0)
        displayer = Displayer(title="Isomap algorithms comparison") \
            .load(title="Swiss roll from %i samples." % (samples,), data=data, color=c)

        start = time()
        result = manifold.Isomap(neighbors, to_dimension,
                                 path_method='D').fit_transform(data)
        elapsed = time() - start

        displayer \
            .load(
                title="SKLearn's Isomap (%i neighbors, dijkstra, taking %.1fs)" % (neighbors, elapsed),
                data=result,
                color=c)

        start = time()
        result = manifold.Isomap(neighbors, to_dimension,
                                 path_method='FW').fit_transform(data)
        elapsed = time() - start

        displayer \
            .load(
                title="SKLearn's Isomap (%i neighbors, floyd-warshall, taking %.1fs)" % (neighbors, elapsed),
                data=result,
                color=c)

        start = time()
        result = algorithms \
            .Isomap(nearest_method='e', e=epsilon, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        displayer.load(title="E-Isomap (epsilon=%i, dijkstra, %.1fs)" %
                       (epsilon, elapsed),
                       data=result,
                       color=c)

        start = time()
        result = algorithms \
            .Isomap(nearest_method='e', shortest_path_method='fw', e=epsilon, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        displayer.load(title="E-Isomap (epsilon=%i, floyd-warshall, %.1fs)" %
                       (epsilon, elapsed),
                       data=result,
                       color=c)

        start = time()
        result = algorithms \
            .Isomap(k=neighbors, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        displayer.load(title="K-Isomap (%i neighbors, dijkstra, %.1fs)" %
                       (neighbors, elapsed),
                       data=result,
                       color=c)

        start = time()
        result = algorithms \
            .Isomap(k=neighbors, n_components=to_dimension, shortest_path_method='fw') \
            .transform(data)
        elapsed = time() - start

        displayer.load(title="K-Isomap (%i neighbors, floyd-warshall, %.1fs)" %
                       (neighbors, elapsed),
                       data=result,
                       color=c)

        displayer.show()