def calc_stats(test_label, results_file, human_suggestions_file, stats_file): """Calc stats and write to results_file. Arguments: - `query_list`: - `suggestion_dict`: """ query_list, suggestion_dict = get_output_from_file(test_label, results_file) human_suggestion_dict = get_human_suggestions(test_label, human_suggestions_file) dummy_spell_checker = spell_checker.SpellChecker() args = [query_list, suggestion_dict, human_suggestion_dict] EP = utils.get_EP(*args) ER = utils.get_ER(*args) EF1 = utils.get_HM(EP, ER) stats = [EP, ER, EF1] # print 'stats', stats f = open(stats_file, 'a') stats_str = 'Timestamp: {0}\tLabel: {1}\tEP: {3}\tER: {4}\t \ EF1: {5}\tNum queries: {2}\n'.format( str(datetime.now()), test_label, len(query_list), *stats) print 'stats_str', stats_str f.write(stats_str) f.close()
def get_EF1_measure(self, human_suggestion_dict): """Return EF1 value for the performance as judged by human_suggestion_dict. Arguments: - `human_suggestion_dict`: dict of query -> list of human-annotated suggestions """ args = [self.query_list, self.suggestion_dict, human_suggestion_dict] return utils.get_HM (utils.get_EP(*args), utils.get_ER(*args))
def test_get_HM_corner_cases(self): self.assertAlmostEqual(utils.get_HM(0.0, 3.0), 0.0, 1) self.assertAlmostEqual(utils.get_HM(0.3, 0.0), 0.0, 1) self.assertAlmostEqual(utils.get_HM(0.0, 0.0), 0.0, 1)
def test_get_HM(self): self.assertAlmostEqual(utils.get_HM(3, 3), 3, 1) self.assertAlmostEqual(utils.get_HM(3, 0), 0, 1) self.assertAlmostEqual(utils.get_HM(0.3, 0.7), 0.42, 1) self.assertAlmostEqual(utils.get_HM(0.5, 0.5), 0.5, 1) self.assertAlmostEqual(utils.get_HM(0.1, 0.9), 0.18, 1)