cosanlab / nltools

Python toolbox for analyzing imaging data
https://nltools.org
MIT License
122 stars 44 forks source link

Error with predict constructor using mask #2

Closed jmol048 closed 8 years ago

jmol048 commented 9 years ago
snv_mask = nb.load('~/roi_niftis/vta_sn.nii');
svr = Predict(dat,Y,algorithm='svr',subject_id = holdout, 
          mask=snv_mask,output_dir=out_folder, cv_dict = {'loso':holdout}, 
          **{'kernel':"linear"})

Returns this error:

ValueError Traceback (most recent call last)

in () 5 svr = Predict(dat,Y,algorithm='svr',subject_id = holdout, 6 mask=snv_mask,output_dir=out_folder, cv_dict = {'loso':holdout}, ----> 7 **{'kernel':"linear"}) 8 #print svr 9 #svr.predict() python2.7/site-packages/nltools/analysis.pyc in **init**(self, data, Y, subject_id, algorithm, cv_dict, mask, output_dir, **kwargs) 72 raise ValueError("data is not a nibabel instance") 73 self.nifti_masker = NiftiMasker(mask_img=mask) ---> 74 self.data = self.nifti_masker.fit_transform(data) 75 76 if self.data.shape[0]!= len(Y): python2.7/site-packages/nilearn/input_data/base_masker.pyc in fit_transform(self, X, y, confounds, **fit_params) 248 ).transform(X, confounds=confounds) 249 else: --> 250 return self.fit(**fit_params).transform(X, confounds=confounds) 251 else: 252 # fit method of arity 2 (supervised transformation) python2.7/site-packages/nilearn/input_data/nifti_masker.pyc in transform(self, imgs, confounds) 218 219 return self.transform_single_imgs( --> 220 imgs, confounds, sample_mask=self.sample_mask) python2.7/site-packages/nilearn/input_data/base_masker.pyc in transform_single_imgs(self, imgs, confounds, copy, sample_mask) 158 confounds=confounds, 159 copy=copy, --> 160 sample_mask=sample_mask 161 ) 162 return data python2.7/site-packages/sklearn/externals/joblib/memory.pyc in **call**(self, _args, *_kwargs) 279 280 def **call**(self, _args, *_kwargs): --> 281 return self.func(_args, *_kwargs) 282 283 def call_and_shelve(self, _args, *_kwargs): python2.7/site-packages/nilearn/input_data/base_masker.pyc in filter_and_mask(imgs, mask_img_, parameters, memory_level, memory, verbose, confounds, copy, sample_mask) 78 print("[%s] Masking and smoothing" % class_name) 79 data = masking.apply_mask(imgs, mask_img_, ---> 80 smoothing_fwhm=parameters['smoothing_fwhm']) 81 82 # Temporal python2.7/site-packages/nilearn/masking.pyc in apply_mask(imgs, mask_img, dtype, smoothing_fwhm, ensure_finite) 559 """ 560 mask_img = _utils.check_niimg_3d(mask_img) --> 561 mask, mask_affine = _load_mask_img(mask_img) 562 mask_img = new_img_like(mask_img, mask, mask_affine) 563 return _apply_mask_fmri(imgs, mask_img, dtype=dtype, python2.7/site-packages/nilearn/masking.pyc in _load_mask_img(mask_img, allow_empty) 58 raise ValueError('Given mask is not made of 2 values: %s' 59 '. Cannot interpret as true or false' ---> 60 % values) 61 62 mask = _utils.as_ndarray(mask, dtype=bool) ValueError: Given mask is not made of 2 values: [ 0. 1. 2.]. Cannot interpret as true or false The odd thing is that using nilearn.apply_mask with the same mask works without causing errors- this works- masked_data = apply_mask(dat,snv_mask)
ljchang commented 9 years ago

Thanks @jmol048 I'll add a check soon to make sure mask is binary to fix this problem and also a check that Y is binary for classification.

ljchang commented 8 years ago

This bug is likely not an issue anymore as it was based on a very old version of the code base and before the introduction of the data.Brain_Data class. I'm going to assume this is addressed and close for now, but feel free to revisit it if the problem persists.