rpomponio / neuroHarmonize

Harmonization tools for multi-site neuroimaging analysis. Implemented as a python package. Harmonization of MRI, sMRI, dMRI, fMRI variables with support for NIFTI images. Complements the work in Neuroimage by Pomponio et al. (2019).
https://pypi.org/project/neuroHarmonize/
MIT License
79 stars 28 forks source link

can size of train and test set differ? #48

Closed hannahhacker closed 3 months ago

hannahhacker commented 3 months ago

Hi, thank you so much for this package. I´m Hannah, a Master´s student and I am trying to train the model on healthy participants (n=376) and then apply it to my patient groups (n=695). Is it a problem that I have a different number of cases in the train and the test sample? Because I am, getting this error when I try to apply the trained model to the holdout data:

Cell In[25], line 5 my_holdout_data_adj = harmonizationApply(grad1_pat_combat, covars, my_model)

File ~\AppData\Local\anaconda3\envs\tvb\lib\site-packages\neuroHarmonize\harmonizationApply.py:100 in harmonizationApply s_data, stand_mean, var_pooled, mod_mean = applyStandardizationAcrossFeatures(data, design, info_dict, model)

File ~\AppData\Local\anaconda3\envs\tvb\lib\site-packages\neuroHarmonize\harmonizationApply.py:141 in applyStandardizationAcrossFeatures s_data = ((X- stand_mean - mod_mean) / np.dot(np.sqrt(var_pooled), np.ones((1, n_sample))))

ValueError: operands could not be broadcast together with shapes (1000,695) (1000,376)

Thank you for your help!

rpomponio commented 3 months ago

I'll look into this (related to #47 ) and should have it fixed by the end of the day today.

hannahhacker commented 3 months ago

Thank you so much!

rpomponio commented 3 months ago

@hannahhacker Please try running your code with the latest dev version. You'll need to upgrade the package to 2.4.5:

pip install git+https://github.com/rpomponio/neuroHarmonize --upgrade

If this works I will distribute again on the Packaging Index.

hannahhacker commented 3 months ago

It worked now! Thank you so much!