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)
| 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, |