from Orange.feature.scoring import score_all
def top_rated(scores, n, highest_best=True):
"""Return n top-rated features from the list of scores.
- :param scores: a list such as the one returned by
- :param n: number of features to select.
+ A list such as the one returned by :func:`.score_all`
+ :param int n: Number of features to select.
+ :param bool highest_best:
+ If true, the features that are scored higher are preferred.
- :param highest_best: if true, the features that are scored higher are preferred
- :type highest_best: bool
- return [x for x in \
- sorted(scores, key=itemgetter(1), reverse=True)[:n]
+ return [f for f, score in
+ sorted(scores, key=itemgetter(1), reverse=highest_best)[:n]]
def above_threshold(scores, threshold=0.0):
"""Return features (without scores) with scores above or
equal to a specified threshold.