Exemplo n.º 1
0
def test_plot_1d_cluster_custom_1():
    data_reduced_1d = reducer(data, ndims=1)
    NUM_CLUSTERS = 4
    geo = plot.plot(data_reduced_1d,
                    cluster='KMeans',
                    n_clusters=NUM_CLUSTERS,
                    show=False)
    assert all([i.shape[1] == 1
                for i in geo.data]) and len(geo.ax.get_lines()) == NUM_CLUSTERS
Exemplo n.º 2
0
def test_plot_2d_cluster():
    data_reduced_2d = reducer(data, ndims=2)
    NUM_CLUSTERS = 4
    geo = plot.plot(data_reduced_2d,
                    cluster={
                        'model': 'KMeans',
                        'params': {
                            'n_clusters': NUM_CLUSTERS
                        }
                    },
                    show=False)
    assert all([i.shape[1] == 2
                for i in geo.data]) and len(geo.ax.get_lines()) == NUM_CLUSTERS
Exemplo n.º 3
0
def test_plot_3d_animate_cluster():
    NUM_CLUSTERS = 4
    data_reduced_3d = reducer(data, ndims=3)
    geo = plot.plot(data_reduced_3d,
                    cluster={
                        'model': 'KMeans',
                        'params': {
                            'n_clusters': NUM_CLUSTERS
                        }
                    },
                    animate=True,
                    show=False)
    assert all([i.shape[1] == 3 for i in geo.data])
Exemplo n.º 4
0
def test_plot_2d_animate_cluster():
    NUM_CLUSTERS = 4
    data_reduced_2d = reducer(data, ndims=2)
    with pytest.raises(Exception) as e_info:
        plot.plot(data_reduced_2d,
                  cluster={
                      'model': 'KMeans',
                      'params': {
                          'n_clusters': NUM_CLUSTERS
                      }
                  },
                  animate=True,
                  show=False)
Exemplo n.º 5
0
def test_reduce_params_UMAP():
    from umap import UMAP
    data1 = np.random.rand(20, 10)
    params = {
        'n_neighbors': 5,
        'n_components': 2,
        'metric': 'correlation',
        'random_state': 1234
    }
    # testing override of n_dims by n_components. Should raise UserWarning due to conflict
    hyp_data = reducer(data1,
                       reduce={
                           'model': 'UMAP',
                           'params': params
                       },
                       ndims=3)
    umap_data = UMAP(**params).fit_transform(data1)
    np.testing.assert_array_equal(hyp_data, umap_data)
Exemplo n.º 6
0
def test_reduce_geo():
    geo = plot(data, show=False)
    reduced_data_3d = reducer(geo, ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 7
0
def test_reduce_IncrementalPCA():
    reduced_data_3d = reducer(data, reduce='IncrementalPCA', ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 8
0
def test_reduce_dims_2d():
    reduced_data_2d = reducer(data, ndims=2)
    assert reduced_data_2d[0].shape == (10, 2)
Exemplo n.º 9
0
def test_reduce_dims_1d():
    reduced_data_1d = reducer(data, ndims=1)
    assert reduced_data_1d[0].shape == (10, 1)
Exemplo n.º 10
0
def test_reduce_TSNE():
    reduced_data_3d = reducer(data, reduce='TSNE', ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 11
0
def test_reduce_SparsePCA():
    reduced_data_3d = reducer(data, model='SparsePCA', ndims=3)
    assert reduced_data_3d[0].shape == (100, 3)
Exemplo n.º 12
0
def test_reduce_TruncatedSVD():
    reduced_data_3d = reducer(data, reduce='TruncatedSVD', ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 13
0
def test_reduce_FastICA():
    reduced_data_3d = reducer(data, reduce='FastICA', ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 14
0
def test_reduce_MDS():
    reduced_data_3d = reducer(data, reduce='MDS', ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 15
0
def test_reduce_UMAP():
    reduced_data_3d = reducer(data, reduce='UMAP', ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 16
0
def test_reduce_LocallyLinearEmbedding():
    reduced_data_3d = reducer(data, reduce='LocallyLinearEmbedding', ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 17
0
def test_reduce_SpectralEmbedding():
    reduced_data_3d = reducer(data, reduce='SpectralEmbedding', ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 18
0
def test_reduce_Isomap():
    reduced_data_3d = reducer(data, reduce='Isomap', ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 19
0
def test_reduce_MiniBatchSparsePCA():
    reduced_data_3d = reducer(data, reduce='MiniBatchSparsePCA', ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 20
0
def test_plot_2d_animate():
    data_reduced_2d = reducer(data, ndims=2)
    with pytest.raises(Exception) as e_info:
        plot.plot(data_reduced_2d, animate=True, show=False)
Exemplo n.º 21
0
def test_reduce_KernelPCA():
    reduced_data_3d = reducer(data, reduce='KernelPCA', ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 22
0
def test_plot_2d():
    data_reduced_2d = reducer(data, ndims=2)
    geo = plot.plot(data_reduced_2d, show=False)
    assert all([i.shape[1] == 2 for i in geo.data])
Exemplo n.º 23
0
def test_reduce_FactorAnalysis():
    reduced_data_3d = reducer(data, reduce='FactorAnalysis', ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 24
0
# -*- coding: utf-8 -*-

from builtins import range

import numpy as np

from hypertools.tools.reduce import reduce as reducer
from hypertools.plot.plot import plot

data = [
    np.random.multivariate_normal(np.zeros(4), np.eye(4), size=10)
    for i in range(2)
]
reduced_data_2d = reducer(data, ndims=2)
reduced_data_1d = reducer(data, ndims=1)


def test_reduce_is_list():
    reduced_data_3d = reducer(data)
    assert type(reduced_data_3d) is list


def test_reduce_is_array():
    reduced_data_3d = reducer(data, ndims=3)
    assert isinstance(reduced_data_3d[0], np.ndarray)


def test_reduce_dims_3d():
    reduced_data_3d = reducer(data, ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 25
0
def test_reduce_MiniBatchDictionaryLearning():
    reduced_data_3d = reducer(data,
                              reduce='MiniBatchDictionaryLearning',
                              ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)
Exemplo n.º 26
0
def test_reduce_is_list():
    reduced_data_3d = reducer(data)
    assert type(reduced_data_3d) is list
Exemplo n.º 27
0
def test_plot_1d():
    data_reduced_1d = reducer(data, ndims=1)
    geo = plot.plot(data_reduced_1d, show=False)
    assert all([i.shape[1] == 1 for i in geo.data])
Exemplo n.º 28
0
def test_reduce_is_array():
    reduced_data_3d = reducer(data, ndims=3)
    assert isinstance(reduced_data_3d[0], np.ndarray)
Exemplo n.º 29
0
def test_plot_3d():
    data_reduced_3d = reducer(data, ndims=3)
    geo = plot.plot(data_reduced_3d, show=False)
    assert all([i.shape[1] == 3 for i in geo.data])
Exemplo n.º 30
0
def test_reduce_dims_3d():
    reduced_data_3d = reducer(data, ndims=3)
    assert reduced_data_3d[0].shape == (10, 3)