def train(self, filename): data = self.load_data(filename) m = MaxentModel() m.begin_add_event() for word, history in data: features = self.generate_features(word, history) m.add_event(features, word) m.end_add_event() m.train() self.model = m
def main(): m = MaxentModel() data = load_data() m.begin_add_event() for vals, label in data: features = extract_features(vals) m.add_event(features, label) m.end_add_event() m.train() print 'Trained' test_instance = [6.7, 3.1, 5.6, 2.4] test_features = extract_features(test_instance) result = m.eval_all(test_features) print 'Result' print result