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.base 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 sensitivity_analyzer = property(fget=lambda self:self.__sensitivity_analyzer,
134 doc="Measure which was used to do selection")
135
136
138 """Feature elimination through the list of FeatureSelection's.
139
140 Given as list of FeatureSelections it applies them in turn.
141 """
142
143 nfeatures = StateVariable(
144 doc="Number of features before each step in pipeline")
145
146
147 - def __init__(self,
148 feature_selections,
149 **kwargs
150 ):
151 """Initialize feature selection pipeline
152
153 :Parameters:
154 feature_selections : lisf of FeatureSelection
155 selections which to use. Order matters
156 """
157
158 FeatureSelection.__init__(self, **kwargs)
159
160 self.__feature_selections = feature_selections
161 """Selectors to use in turn"""
162
163
164 - def __call__(self, dataset, testdataset=None, **kwargs):
197
198 feature_selections = property(fget=lambda self:self.__feature_selections,
199 doc="List of `FeatureSelections`")
200