1
2
3
4
5
6
7
8
9 """Feature selection base class and related stuff base classes and helpers."""
10
11 __docformat__ = 'restructuredtext'
12
13 from mvpa.featsel.helpers import FractionTailSelector
14 from mvpa.misc.state import StateVariable, Stateful
15
16 if __debug__:
17 from mvpa.misc import debug
18
20 """Base class for any feature selection
21
22 Base class for Functors which implement feature selection on the
23 datasets.
24 """
25
26 selected_ids = StateVariable(enabled=False)
27
31
32
33 - def __call__(self, dataset, testdataset=None):
34 """Invocation of the feature selection
35
36 :Parameters:
37 dataset : Dataset
38 dataset used to select features
39 testdataset : Dataset
40 dataset the might be used to compute a stopping criterion
41
42 Returns a tuple with the dataset containing the selected features.
43 If present the tuple also contains the selected features of the
44 test dataset. Derived classes must provide interface to access other
45 relevant to the feature selection process information (e.g. mask,
46 elimination step (in RFE), etc)
47 """
48 raise NotImplementedError
49
50
51
53 """Feature elimination.
54
55 A `FeaturewiseDatasetMeasure` is used to compute sensitivity maps given a certain
56 dataset. These sensitivity maps are in turn used to discard unimportant
57 features.
58 """
59
60 sensitivity = StateVariable(enabled=False)
61
67 """Initialize feature selection
68
69 :Parameters:
70 sensitivity_analyzer : FeaturewiseDatasetMeasure
71 sensitivity analyzer to come up with sensitivity
72 feature_selector : Functor
73 Given a sensitivity map it has to return the ids of those
74 features that should be kept.
75
76 """
77
78
79 FeatureSelection.__init__(self, **kwargs)
80
81 self.__sensitivity_analyzer = sensitivity_analyzer
82 """Sensitivity analyzer to use once"""
83
84 self.__feature_selector = feature_selector
85 """Functor which takes care about removing some features."""
86
87
88
89 - def __call__(self, dataset, testdataset=None):
131
132
133
135 """Feature elimination through the list of FeatureSelection's.
136
137 Given as list of FeatureSelections it applies them in turn.
138 """
139
140 nfeatures = StateVariable(
141 doc="Number of features before each step in pipeline")
142
143
144 - def __init__(self,
145 feature_selections,
146 **kwargs
147 ):
148 """Initialize feature selection pipeline
149
150 :Parameters:
151 feature_selections : lisf of FeatureSelection
152 selections which to use. Order matters
153 """
154
155 FeatureSelection.__init__(self, **kwargs)
156
157 self.__feature_selections = feature_selections
158 """Selectors to use in turn"""
159
160
161 - def __call__(self, dataset, testdataset=None, **kwargs):
194
195 feature_selections = property(fget=lambda self:self.__feature_selections,
196 doc="List of `FeatureSelections`")
197