'Returns a list with the most informative features (terms), using information gain.
This is a subset of Model.features that can be used to build a Classifier
that is faster (less features = less matrix columns) but still efficient.
The given document frequency threshold excludes features that occur in
less than the given percentage of documents (i.e., outliers).'

def feature_selection(self, top=100, method=CHISQUARED, threshold=0.0, weighted=False):

    if (method is None):
        f = (lambda w: 1.0)
    if (method in (X2, CHISQUARE, CHISQUARED, 'X2')):
        f = (lambda w: (1.0 - self.x2(w)))
    if (method in (IG, INFOGAIN)):
        f = self.ig
    if (method in (GR, GAINRATIO)):
        f = self.gr
    if (method == DF):
        f = self.df
    if hasattr(method, '__call__'):
        f = method
    subset = ((f(w), w) for w in self.terms if (self.df(w) >= threshold))
    subset = sorted(subset, key=itemgetter(1))
    subset = sorted(subset, key=itemgetter(0), reverse=True)
    subset = subset[:(top if (top is not None) else len(subset))]
    subset = (subset if weighted else [w for (x, w) in subset])
    return subset
