From 457ea41e94cfd6a088fce815e829d5b63f9b1742 Mon Sep 17 00:00:00 2001 From: maeries <8ij4neqiu@mozmail.com> Date: Sun, 23 Mar 2025 21:28:12 +0100 Subject: [PATCH] added k factor validation and set k accordingly --- main.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 4fa5a3a..988983b 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ from tools import * from world_ranking_list import get_world_ranking_html # Constants for Elo calculation -K_FACTOR = 10 +K_FACTOR = 15 INITIAL_ELO = 1500 # Starting Elo for all teams @@ -467,6 +467,30 @@ class EloSystem: dpi=100) plt.close() + def optimize_k(self): + self.load_and_process_csv_files() + error_history = [] + for comp in self.competition_history: + if self.get_competition_name(comp) in ("DE", "EA", "AT", "NL", "AA", "ES", "UK", "IT", "CZ", "CH"): + if 2020 > self.get_competition_date(comp).year > 2016: + results = self.competition_history[comp]['results'] + error = 0 + for result in results: + error = error + abs(result[3] / K_FACTOR) + error = error / len(results) + error_history.append(error) + pass + # calculate RMSE of the list of error + squared_errors = [error ** 2 for error in error_history] + mean_squared_error = sum(squared_errors) / len(squared_errors) + rmse = math.sqrt(mean_squared_error) + + print(f"K of {K_FACTOR} results in a prediction RMSE of {rmse}") + + +def run_optimize_k(): + elo_system = EloSystem('csv_files', 'public/elo_website_combustion', "combustion") + elo_system.optimize_k() def main(): """Main function to run the Elo ranking system""" -- GitLab