def test_mapped_classifier_sensitivity_analyzer(self, clf): """Test sensitivity of the mapped classifier """ # Assuming many defaults it is as simple as mclf = FeatureSelectionClassifier( clf, SensitivityBasedFeatureSelection( OneWayAnova(), FractionTailSelector(0.5, mode='select', tail='upper')), enable_ca=['training_stats']) sana = mclf.get_sensitivity_analyzer(postproc=sumofabs_sample(), enable_ca=["sensitivities"]) # and lets look at all sensitivities dataset = datasets['uni2small'] # and we get sensitivity analyzer which works on splits sens = sana(dataset) self.assertEqual(sens.shape, (1, dataset.nfeatures))
def test_union_feature_selection(self): # two methods: 5% highes F-scores, non-zero SMLR weights fss = [SensitivityBasedFeatureSelection( OneWayAnova(), FractionTailSelector(0.05, mode='select', tail='upper')), SensitivityBasedFeatureSelection( SMLRWeights(SMLR(lm=1, implementation="C"), postproc=sumofabs_sample()), RangeElementSelector(mode='select'))] fs = CombinedFeatureSelection(fss, method='union') od_union = fs(self.dataset) self.assertTrue(fs.method == 'union') # check output dataset self.assertTrue(od_union.nfeatures <= self.dataset.nfeatures) # again for intersection fs = CombinedFeatureSelection(fss, method='intersection') od_intersect = fs(self.dataset) assert_true(od_intersect.nfeatures < od_union.nfeatures)
from mvpa2.generators.partition import NFoldPartitioner from mvpa2.generators.resampling import Balancer from mvpa2.misc.errorfx import mean_mismatch_error from mvpa2.misc.transformers import Absolute, \ DistPValue from mvpa2.measures.base import Measure, \ TransferMeasure, RepeatedMeasure, CrossValidation from mvpa2.measures.anova import OneWayAnova, CompoundOneWayAnova from mvpa2.measures.irelief import IterativeRelief, IterativeReliefOnline, \ IterativeRelief_Devel, IterativeReliefOnline_Devel _MEASURES_2_SWEEP = [ OneWayAnova(), CompoundOneWayAnova(postproc=sumofabs_sample()), IterativeRelief(), IterativeReliefOnline(), IterativeRelief_Devel(), IterativeReliefOnline_Devel() ] if externals.exists('scipy'): from mvpa2.measures.corrcoef import CorrCoef _MEASURES_2_SWEEP += [ CorrCoef(), # that one is good when small... handle later #CorrCoef(pvalue=True) ] class SensitivityAnalysersTests(unittest.TestCase):
from mvpa2.generators.partition import NFoldPartitioner from mvpa2.generators.resampling import Balancer from mvpa2.misc.errorfx import mean_mismatch_error from mvpa2.misc.transformers import Absolute, \ DistPValue from mvpa2.measures.base import Measure, \ TransferMeasure, RepeatedMeasure, CrossValidation from mvpa2.measures.anova import OneWayAnova, CompoundOneWayAnova from mvpa2.measures.irelief import IterativeRelief, IterativeReliefOnline, \ IterativeRelief_Devel, IterativeReliefOnline_Devel _MEASURES_2_SWEEP = [ OneWayAnova(), CompoundOneWayAnova(postproc=sumofabs_sample()), IterativeRelief(), IterativeReliefOnline(), IterativeRelief_Devel(), IterativeReliefOnline_Devel() ] if externals.exists('scipy'): from mvpa2.measures.corrcoef import CorrCoef _MEASURES_2_SWEEP += [ CorrCoef(), # that one is good when small... handle later #CorrCoef(pvalue=True) ] class SensitivityAnalysersTests(unittest.TestCase): def setUp(self): self.dataset = datasets['uni2large']