Example ¨Correcting from pandas.DataFrame as Data¨ needs a data transpose not to fail with shape not aligned
Closed this issue · 1 comments
From @FinLouarn at ncullen93/neuroCombat#6
The first example ¨Correcting from Numpy Array as Data¨ works smoothly,
but the second example ¨Correcting from pandas.DataFrame as Data¨ fails with the following error of shape not aligned, unless you feed neuroCombat with data.T in stead of data.
python 3.7.7
pandas 0.25.3
ValueError Traceback (most recent call last)
in
15 batch_col=batch_col,
16 discrete_cols=discrete_cols,
---> 17 continuous_cols=continuous_cols)
/neuroCombat/neuroCombat/neuroCombat.py in neuroCombat(data, covars, batch_col, discrete_cols, continuous_cols)
97 # standardize data across features
98 print('Standardizing data across features..')
---> 99 s_data, s_mean, v_pool = standardize_across_features(data, design, info_dict)
100
101 # fit L/S models and find priors
/neuroCombat/neuroCombat/neuroCombat.py in standardize_across_features(X, design, info_dict)
159 sample_per_batch = info_dict['sample_per_batch']
160
--> 161 B_hat = np.dot(np.dot(la.inv(np.dot(design.T, design)), design.T), X.T)
162 grand_mean = np.dot((sample_per_batch/ float(n_sample)).T, B_hat[:n_batch,:])
163 var_pooled = np.dot(((X - np.dot(design, B_hat).T)**2), np.ones((n_sample, 1)) / float(n_sample))
<array_function internals> in dot(*args, **kwargs)
ValueError: shapes (8,57) and (22283,57) not aligned: 57 (dim 1) != 22283 (dim 0)
@FinLouarn [features, samples]
is indeed the required format for our latest release (0.2.7), for both a numpy array or pandas DataFrame.