MCPcopy Index your code
hub / github.com/clips/pattern / feature_selection

Method feature_selection

pattern/vector/__init__.py:1178–1188  ·  view source on GitHub ↗

Returns the top unpredictable (or original) 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.

(self, top=100, method=INFOGAIN, verbose=False)

Source from the content-addressed store, hash-verified

1176 IG = ig = infogain = gain = information_gain
1177
1178 def feature_selection(self, top=100, method=INFOGAIN, verbose=False):
1179 """ Returns the top unpredictable (or original) features (terms), using information gain.
1180 This is a subset of Model.features that can be used to build a Classifier
1181 that is faster (less features = less matrix columns) but still efficient.
1182 """
1183 if method == IG:
1184 subset = ((self.information_gain(w), w) for w in self.terms)
1185 subset = sorted(subset, key=itemgetter(1))
1186 subset = sorted(subset, key=itemgetter(0), reverse=True)
1187 subset = [w for ig, w in subset[:top]]
1188 return subset
1189
1190 def filter(self, features=[]):
1191 """ Returns a new Model with documents only containing the given list of features,

Callers 1

Calls 1

information_gainMethod · 0.95

Tested by 1