def predict_wins_by_ratio(data_cut = 100, plot = True): players, _ = tools.create_stats(data_cut) _, games = tools.read_db() predictions = [] results = [] for game in games[data_cut:]: team_red = Team() team_black = Team() for player in players: if player['id'] == game['red0'] or player['id'] == game['red1']: team_red.add_player(player) if player['id'] == game['black0'] or player['id'] == game['black1']: team_black.add_player(player) probability = team_red.strength_by_goals / (team_red.strength_by_goals + team_black.strength_by_goals) predictions.append(probability) if (game['score_red'] > game['score_black']): results.append(1) else: results.append(0) predictions = np.array(predictions) results = np.array(results) MAE = np.mean(np.abs(predictions - results)) if plot: print MAE return MAE
def predict_random_goals(data_cut = 100, plot = True): players, _ = tools.create_stats(data_cut) _, games = tools.read_db() predictions = [] results = [] for game in games[data_cut:]: team_red = Team() team_black = Team() for player in players: if player['id'] == game['red0'] or player['id'] == game['red1']: team_red.add_player(player) if player['id'] == game['black0'] or player['id'] == game['black1']: team_black.add_player(player) if np.random.rand() > 0.5: predictions.append(6 - np.random.randint(0,6)) else: predictions.append(np.random.randint(0,6) - 6) if (game['score_red'] > game['score_black']): results.append(1) else: results.append(0) predictions = np.array(predictions) results = np.array(results) MAE = np.mean(np.abs(predictions - results)) if plot: print MAE return MAE
def predict_goals_by_effictivity(data_cut = 100, plot = True): players, _ = tools.create_stats(data_cut) _, games = tools.read_db() predictions = [] results = [] for game in games[data_cut:]: team_red = Team() team_black = Team() for player in players: if player['id'] == game['red0'] or player['id'] == game['red1']: team_red.add_player(player) if player['id'] == game['black0'] or player['id'] == game['black1']: team_black.add_player(player) effectivity_red = team_red.offensive_strength_by_time # * team_black.defensive_strength_by_time effectivity_black = team_black.offensive_strength_by_time # * team_red.defensive_strength_by_time if effectivity_red > effectivity_black: predicted_score_black = effectivity_black / effectivity_red * 6 predictions.append(6 - predicted_score_black) if plot: print "Prediction: red wins 6:" + str(int(round(predicted_score_black))), " real outcome: ", str(game['score_red']) + ":" + str(game['score_black']) else: predicted_score_red = effectivity_red / effectivity_black * 6 predictions.append(predicted_score_red - 6) if plot: print "Prediction: black wins 6:" + str(int(round(predicted_score_red))), " real outcome: ", str(game['score_black']) + ":" + str(game['score_red']) results.append(game['score_red'] - game['score_black']) predictions = np.array(predictions) results = np.array(results) MAE = np.mean(np.abs(predictions - results)) if plot: print MAE return MAE
def loadReminders(self): try: self.reminders = read_db(self, 'tell') except GrumbleError: self.reminders = {}
def load_database(phenny): try: return read_db(phenny, 'reminders') except GrumbleError: return {}
def loadAliases(self): try: nick_aliases = read_db(self, 'alias') except GrumbleError: nick_aliases = []
def setup(phenny): try: phenny.queue_data = read_db(phenny, 'queue') except GrumbleError: logger.debug('queue database read failed, initializing data') phenny.queue_data = {}