From 36e2f8205f6f0087c15cbc2ae00495eedc173efa Mon Sep 17 00:00:00 2001 From: Tal Yarkoni Date: Mon, 26 Nov 2018 09:47:30 -0600 Subject: [PATCH] replace sklearn's deprecated RandomizedPCA with PCA and add checks on # of components --- neurosynth/analysis/cluster.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/neurosynth/analysis/cluster.py b/neurosynth/analysis/cluster.py index a4b5cd3..7b895f2 100644 --- a/neurosynth/analysis/cluster.py +++ b/neurosynth/analysis/cluster.py @@ -158,13 +158,22 @@ def magic(dataset, method='coactivation', roi_mask=None, reference = roi if reduce_reference is not None: + + # For non-coactivation-based approaches, transpose the data matrix + transpose = (method == 'coactivation') + if isinstance(reduce_reference, string_types): + + # Number of components can't exceed feature count or cluster count + n_feat = len(reference.data.T if transpose else reference.data) + n_components = min(n_components, n_feat) + if n_clusters is not None: + n_components = min(n_components, n_clusters) + reduce_reference = { - 'pca': sk_decomp.RandomizedPCA, + 'pca': sk_decomp.PCA, 'ica': sk_decomp.FastICA }[reduce_reference](n_components) - - transpose = (method == 'coactivation') reference = reference.transform(reduce_reference, transpose=transpose) if method == 'coactivation':