Skip to content

Instantly share code, notes, and snippets.

@roh26it
Created March 22, 2023 13:19
Show Gist options
  • Save roh26it/90fcceb7356e8c732c92c928e6865028 to your computer and use it in GitHub Desktop.
Save roh26it/90fcceb7356e8c732c92c928e6865028 to your computer and use it in GitHub Desktop.
A demo to showcase Elo ratings for a multiplayer use case
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from multielo import MultiElo
# Initialize the Elo ratings and history
recipes = ['Recipe 1', 'Recipe 2', 'Recipe 3']
elo_ratings = np.array([1500, 1500, 1500])
elo_history = [np.array([1500]), np.array([1500]), np.array([1500])]
elo = MultiElo()
while True:
print("Please rank the recipes from 1 (best) to 3 (worst).")
ranks = [int(input(f"Rank for {recipe}: ")) for recipe in recipes]
# Update ratings based on user input
new_ratings = elo.get_new_ratings(elo_ratings, ranks)
# Update the rating history
for idx, rating in enumerate(new_ratings):
elo_history[idx] = np.append(elo_history[idx], rating)
elo_ratings = new_ratings
print("Current Elo Ratings:", elo_ratings)
plot_choice = input("Would you like to plot the Elo rating changes? (yes/no): ")
if plot_choice.lower() == 'yes':
for idx, recipe in enumerate(recipes):
plt.plot(elo_history[idx], label=recipe)
plt.xlabel("Number of Iterations")
plt.ylabel("Elo Rating")
plt.title("Elo Rating Changes")
plt.legend()
plt.show()
continue_choice = input("Do you want to continue ranking recipes? (yes/no): ")
if continue_choice.lower() == 'no':
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment