Ignore:
Timestamp:
08/02/13 16:10:29 (9 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Preserve the domain's meta attributes and class_vars.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/feature/selection.py

    r11646 r11647  
    33from operator import itemgetter 
    44 
     5import Orange.data 
    56import Orange.core as orange 
    67 
    78from Orange.feature.scoring import score_all 
     9 
     10 
     11def _select_features_subset(data, features): 
     12    """Select the `features` from the `data`. 
     13 
     14    .. note:: 
     15        The `features` must be a subset of the `data.domain.features`. 
     16 
     17    """ 
     18    def as_descriptor(arg): 
     19        """Ensure `arg` is an descriptor from `data.domain`""" 
     20        return data.domain[arg] 
     21 
     22    features = map(as_descriptor, features) 
     23    domain = Orange.data.Domain(features, data.domain.class_var, 
     24                                class_vars=data.domain.class_vars) 
     25    domain.add_metas(data.domain.get_metas()) 
     26    return Orange.data.Table(domain, data) 
    827 
    928 
     
    5372    :type n: int 
    5473    :rtype: :obj:`Orange.data.Table` 
    55     """ 
    56     return data.select(top_rated(scores, n) + [data.domain.classVar.name]) 
     74 
     75    """ 
     76    features = top_rated(scores, n) 
     77    return _select_features_subset(data, features) 
    5778 
    5879selectBestNAtts = select 
     
    7596    :rtype: :obj:`Orange.data.Table` 
    7697    """ 
    77     return data.select(above_threshold(scores, threshold) + \ 
    78                        [data.domain.classVar.name]) 
     98    features = above_threshold(scores, threshold) 
     99    return _select_features_subset(data, features) 
    79100 
    80101selectAttsAboveThresh = select_above_threshold 
Note: See TracChangeset for help on using the changeset viewer.