def test_get_wins_loses(self): same_teams_pairs = {(1, 4): [1, 2]} stpc = SameTeamsPairsContainer(same_teams_pairs) self.assertEqual(stpc.get_wins_loses(1, 4), (1, 2)) self.assertEqual(stpc.get_wins_loses(4, 1), (1, 2)) self.assertEqual(stpc.get_wins_loses(5, 7), (0, 0))
hero_id_to_name = get_hero_id_to_name() def show_win_loses(heroes, hr_id_to_nm): if isinstance(heroes, dict): heroes = heroes.items() for key, value in heroes: if isinstance(key, int): key = (key, ) names = ["{0:20}".format(hero_id_to_name[id]) for id in key] name = "| ".join(names) print "{0} {1:0>5} {2:0>5}".format(name, *value) solo_hr = defaultdict(lambda: [0, 0]) stpc = SameTeamsPairsContainer() dtpc = DifferentTeamsPairsContainer() WIN_INDEX, LOSE_INDEX = 0, 1 same_triple = defaultdict(lambda: [0, 0]) for i, record in enumerate(train_data): radiant_win, radiant, dire = record winners, losers = (radiant, dire) if radiant_win else (dire, radiant) #solo heroes for hero_id in winners: solo_hr[hero_id][WIN_INDEX] += 1 for hero_id in losers: solo_hr[hero_id][LOSE_INDEX] += 1
STAT_FILE_NAME = "stat_data.p" TEST_DATA_FILE_NAME = "test_data16451.p" TEAM_OFFSET = 1000 print "load stat data from {0}".format(STAT_FILE_NAME) stat_data = pickle.load(open(STAT_FILE_NAME, 'rb')) print "load complete" print "load test data from {0}".format(TEST_DATA_FILE_NAME) test_data = pickle.load(open(TEST_DATA_FILE_NAME, 'rb')) print "load complete" solo_hr, stpc, dtpc = stat_data solo_hr = defaultdict(lambda: [0, 0], solo_hr) stpc = SameTeamsPairsContainer(stpc) dtpc = DifferentTeamsPairsContainer(dtpc) tr = FractionTermResolver(TEAM_OFFSET, solo_hr, stpc, dtpc, smoothing=0.5) #tr = OddsTermResolver(TEAM_OFFSET, solo_hr, stpc, dtpc) predictor = PredictorNaiveBayesBigram(TEAM_OFFSET, tr) num_correct = 0.0 num_matches = len(test_data) for record in test_data: radiant_win, radiant, dire = record probability = predictor.predict(radiant, dire) if probability > 0.5001 and radiant_win or probability < 0.4999 and not radiant_win: num_correct += 1.0
def show_win_loses(heroes, hr_id_to_nm): if isinstance(heroes, dict): heroes = heroes.items() for key, value in heroes: if isinstance(key, int): key = (key, ) names = ["{0:20}".format(hero_id_to_name[id]) for id in key] name = "| ".join(names) print "{0} {1:0>5} {2:0>5}".format(name, *value) solo_hr = defaultdict(lambda: [0, 0]) stpc = SameTeamsPairsContainer() dtpc = DifferentTeamsPairsContainer() WIN_INDEX, LOSE_INDEX = 0, 1 same_triple = defaultdict(lambda: [0, 0]) for i, record in enumerate(train_data): radiant_win, radiant, dire = record winners, losers = (radiant, dire) if radiant_win else (dire, radiant) #solo heroes for hero_id in winners: solo_hr[hero_id][WIN_INDEX] += 1 for hero_id in losers: solo_hr[hero_id][LOSE_INDEX] += 1
def setUp(self): self.stpc = SameTeamsPairsContainer()