Ignore:
Timestamp:
04/03/12 07:25:08 (2 years ago)
Author:
blaz <blaz.zupan@…>
Branch:
default
Message:

Some cosmetics and renaming in Orange.feature.selection

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/feature/selection.py

    r10523 r10708  
    77from Orange.feature.scoring import score_all 
    88 
    9  
    10 def best_n(scores, n): 
    11     """Return the best features (without scores) from the list 
     9def top_rated(scores, n, highest_best=True): 
     10    """Return n top-rated features from the list of scores. 
    1211 
    1312    :param scores: a list such as the one returned by 
     
    1716    :type n: int 
    1817    :rtype: :obj:`list` 
    19  
     18    :param highest_best: if true, the features that are scored higher are preferred 
     19    :type highest_best: bool 
    2020    """ 
    2121    return [x[0] for x in \ 
     
    2323            ] 
    2424 
    25 bestNAtts = best_n 
    26  
     25bestNAtts = top_rated 
    2726 
    2827def above_threshold(scores, threshold=0.0): 
     
    4443 
    4544 
    46 def select_best_n(data, scores, n): 
     45def select(data, scores, n): 
    4746    """Construct and return a new data table that includes a 
    4847    class and only the best features from a list scores. 
     
    5756    :rtype: :obj:`Orange.data.Table` 
    5857    """ 
    59     return data.select(best_n(scores, n) + [data.domain.classVar.name]) 
    60  
    61 selectBestNAtts = select_best_n 
     58    return data.select(top_rated(scores, n) + [data.domain.classVar.name]) 
     59 
     60selectBestNAtts = select 
    6261 
    6362 
     
    6564    """Construct and return a new data table that includes a class and 
    6665    features from the list returned by 
    67     :obj:`~Orange.feature.scoring.score_all` that have the score above or 
    68     equal to a specified threshold. 
     66    :obj:`~Orange.feature.scoring.score_all` with higher or equal score 
     67    to a given threshold. 
    6968 
    7069    :param data: a data table 
     
    10099    measl = score_all(data, measure) 
    101100    while len(data.domain.attributes) > 0 and measl[-1][1] < margin: 
    102         data = select_best_n(data, measl, len(data.domain.attributes) - 1) 
     101        data = select(data, measl, len(data.domain.attributes) - 1) 
    103102        measl = score_all(data, measure) 
    104103    return data 
     
    108107 
    109108class FilterAboveThreshold(object): 
    110     """A class wrapper around :obj:`select_above_threshold`; the 
    111     constructor stores the filter parameters that are applied when the 
    112     function is called. 
     109    """A wrapper around :obj:`select_above_threshold`; the 
     110    constructor stores the parameters of the feature selection 
     111    procedure that are then applied when the the selection 
     112    is called with the actual data. 
    113113 
    114114    :param measure: a feature scorer 
     
    116116    :param threshold: threshold for selection. Defaults to 0. 
    117117    :type threshold: float 
    118  
    119     Some examples of how to use this class:: 
    120  
    121         filter = Orange.feature.selection.FilterAboveThreshold(threshold=.15) 
    122         new_data = filter(data) 
    123         new_data = Orange.feature.selection.FilterAboveThreshold(data) 
    124         new_data = Orange.feature.selection.FilterAboveThreshold(data, threshold=.1) 
    125         new_data = Orange.feature.selection.FilterAboveThreshold(data, threshold=.1, 
    126                    measure=Orange.feature.scoring.Gini()) 
    127  
    128     """ 
     118    """ 
     119 
    129120    def __new__(cls, data=None, 
    130121                measure=orange.MeasureAttribute_relief(k=20, m=50), 
     
    158149 
    159150class FilterBestN(object): 
    160     """A class wrapper around :obj:`select_best_n`; the 
     151    """A wrapper around :obj:`select`; the 
    161152    constructor stores the filter parameters that are applied when the 
    162153    function is called. 
     
    187178        ma = score_all(data, self.measure) 
    188179        self.n = min(self.n, len(data.domain.attributes)) 
    189         return select_best_n(data, ma, self.n) 
     180        return select(data, ma, self.n) 
    190181 
    191182FilterBestNAtts = FilterBestN 
     
    230221 
    231222class FilteredLearner(object): 
    232     """A learner that applies the given features selection method and 
    233     then calls the base learner. This learner is needed to properly cross-validate a combination of feature selection and learning. 
     223    """A feature selection wrapper around base learner. When provided data, 
     224     this learner applies a given feature selection method and then calls 
     225     the base learner. 
    234226 
    235227    Here is an example of how to build a wrapper around naive Bayesian learner 
Note: See TracChangeset for help on using the changeset viewer.