Skip to content

Commit

Permalink
handle n_pca < n_samples
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgigante committed Feb 21, 2019
1 parent 560ea76 commit 34243be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions graphtools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ class Data(Base):
def __init__(self, data, n_pca=None, random_state=None, **kwargs):

self._check_data(data)
if n_pca is not None and data.shape[1] <= n_pca:
if n_pca is not None and np.min(data.shape) <= n_pca:
warnings.warn("Cannot perform PCA to {} dimensions on "
"data with {} dimensions".format(n_pca,
data.shape[1]),
"data with min(n_samples, n_features) = {}".format(
n_pca, np.min(data.shape)),
RuntimeWarning)
n_pca = None
try:
Expand Down
6 changes: 6 additions & 0 deletions test/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def test_too_many_n_pca():
build_graph(data, n_pca=data.shape[1])


@warns(RuntimeWarning)
def test_too_many_n_pca():
build_graph(data[:data.shape[1] - 1],
n_pca=data.shape[1] - 1)


@warns(RuntimeWarning)
def test_precomputed_with_pca():
build_graph(squareform(pdist(data)),
Expand Down

0 comments on commit 34243be

Please sign in to comment.