[pymvpa] How could I know which features were selected by feature selection?

Nick Oosterhof n.n.oosterhof at googlemail.com
Tue Apr 19 08:51:02 UTC 2016


> On 19 Apr 2016, at 09:31, <ibinliu at sina.com> <ibinliu at sina.com> wrote:
> 
> Hi all,
> 
> I performed feature selection using anova and wanted the features back to NIfTI. I used the following comment lines but encountered an error:
> 
> 
> 
> clf = LinearCSVMC()
> 
> fsel = SensitivityBasedFeatureSelection(OneWayAnova(),
> 
>                                         FixedNElementTailSelector(2000, mode='select', tail='upper'))
> 
> 
> 
> fclf = FeatureSelectionClassifier(clf, fsel)
> 
> 
> 
> cvte = CrossValidation(fclf, NFoldPartitioner(),
> 
>                        errorfx=lambda p, t: np.mean(p == t),
> 
>                        enable_ca=['stats'])
> 
> cv_results = cvte(ds)
> 
> 
> 
> final_dataset = fclf.mapper.forward(ds)
> 
> 
> 
> print final_dataset
> 
> <Dataset: 128x2000 at float32, <sa: chunks,targets,time_coords,time_indices>, <fa: voxel_indices>, <a: imgaffine,imghdr,imgtype,mapper,voxel_dim,voxel_eldim>>
> 
> 
> 
> nimg = map2nifti(final_dataset)
> 
> nimg.to_filename('features.nii')
> 
> ValueError: array is not broadcastable to correct shape
> 
> 
> 
> Has anyone else had the same errors before?

According to the FAQ [1] it would seem that the clf.mapper.slicearg contains which features were selected. 

It seems you are doing crossvalidation combined with feature selection, which means that for every fold a different subset of features may be selected for training the classifier. As such, you cannot directly convert which features were selected to a nifti volume - except, if you compute a separate volume for each fold.

[1] http://www.pymvpa.org/faq.html#how-do-i-know-which-features-were-finally-selected-by-a-classifier-doing-feature-selection





More information about the Pkg-ExpPsy-PyMVPA mailing list