Exemplo n.º 1
0
def team_rating(resultfile='ncaa_results.csv',
                teamfile='ncaa_teams.txt',
                K=16.):
    '''
        Rate the teams in the game results imported from a CSV file.
        (1) import the W matrix from `resultfile` file.
        (2) compute Elo ratings of all the teams
        (3) return a list of team names sorted by descending order of Elo ratings

        Input:
                resultfile: the csv filename for the game result matrix, a string.
                teamfile: the text filename for the team names, a string.
                K: a float scalar value, which is the k-factor of Elo rating system

        Output:
                top_teams: the list of team names in descending order of their Elo ratings, a python list of string values, such as ['team a', 'team b','team c'].
                top_ratings: the list of elo ratings in descending order, a python list of float values, such as ['600.', '500.','300.'].

    '''
    #########################################
    ## INSERT YOUR CODE HERE
    W = import_W(resultfile)
    N = import_team_names(teamfile)
    top_teams = list()

    M = elo_rating(W, len(N))
    top_ratings = sorted(M, reverse=True)
    ratings_indice = sorted(range(len(M)), reverse=True, key=lambda x: M[x])
    for i in ratings_indice:
        top_teams.append(N[i])
    #########################################
    return top_teams, top_ratings
Exemplo n.º 2
0
def team_rating(resultfile = 'ncaa_results.csv', 
                teamfile='ncaa_teams.txt',
                K=16.):
    ''' 
        Rate the teams in the game results imported from a CSV file.
        (1) import the W matrix from `resultfile` file.
        (2) compute Elo ratings of all the teams
        (3) return a list of team names sorted by descending order of Elo ratings 

        Input: 
                resultfile: the csv filename for the game result matrix, a string.
                teamfile: the text filename for the team names, a string.
                K: a float scalar value, which is the k-factor of Elo rating system

        Output: 
                top_teams: the list of team names in descending order of their Elo ratings, a python list of string values, such as ['team a', 'team b','team c'].
                top_ratings: the list of elo ratings in descending order, a python list of float values, such as ['600.', '500.','300.'].
        
    '''
    W = import_W(resultfile)

    team_names = import_team_names(teamfile)
    
    num_teams = len(team_names)
    
    ratings = elo_rating(W,num_teams,K) 
    
    team_ratings_dict = dict(zip(team_names, ratings))
    
    sorted_dict = dict(sorted(team_ratings_dict.items(), key=lambda x: x[1], reverse=True))
    
    top_teams = list(sorted_dict)
    top_ratings = list(sorted_dict.values())
    return top_teams, top_ratings
Exemplo n.º 3
0
def team_rating(resultfile='ncaa_results.csv',
                teamfile='ncaa_teams.txt',
                K=16.):
    ''' 
        Rate the teams in the game results imported from a CSV file.
        (1) import the W matrix from `resultfile` file.
        (2) compute Elo ratings of all the teams
        (3) return a list of team names sorted by descending order of Elo ratings 

        Input: 
                resultfile: the csv filename for the game result matrix, a string.
                teamfile: the text filename for the team names, a string.
                K: a float scalar value, which is the k-factor of Elo rating system

        Output: 
                top_teams: the list of team names in descending order of their Elo ratings, a python list of string values, such as ['team a', 'team b','team c'].
                top_ratings: the list of elo ratings in descending order, a python list of float values, such as ['600.', '500.','300.'].
        
    '''
    #########################################
    ## INSERT YOUR CODE HERE
    W = import_W(resultfile)
    team_names = import_team_names(teamfile)

    R = elo_rating(W, len(team_names))

    top_teams = [x for _, x in sorted(zip(R, team_names), reverse=True)]
    top_ratings = sorted(R, reverse=True)
    #########################################
    return top_teams, top_ratings
Exemplo n.º 4
0
def team_rating(resultfile='ncaa_results.csv',
                teamfile='ncaa_teams.txt',
                K=16.):
    ''' 
        Rate the teams based upon the game results imported from a CSV file.
        (1) import the W matrix from `resultfile` file.
        (2) compute Elo ratings of all the teams
        (3) return a list of team names sorted by descending order of Elo ratings 

        Input: 
                resultfile: the csv filename for the game result matrix, a string.
                teamfile: the text filename for the team names, a string.
                K: a float scalar value, which is the k-factor of Elo rating system

        Output: 
                top_teams: the list of team names in descending order of their Elo ratings, a python list of string values, such as ['Randolph Col', 'Liberty', ... ].
                top_ratings: the list of elo ratings in descending order, a python list of float values, such as ['600.', '500.','300.'].
        
    '''
    #########################################
    ## INSERT YOUR CODE HERE

    # load team names from 'teamfile'
    team_names = import_team_names(teamfile)
    print(len(team_names))
    # load game results from 'resultfile'
    game_results = list(import_W(resultfile).astype(int))
    print(type(game_results[0][0]))
    print(game_results[0])
    # compute Elo rating of all the teams
    elo_ratings = elo_rating(game_results, len(team_names))
    print(len(elo_ratings))
    # sort team names according to their Elo ratings
    ratings_dict = dict(zip(list(range(len(team_names))), elo_ratings))
    print(len(list(range(len(team_names)))))
    print(list(range(len(team_names)))[0:5])
    print(len(ratings_dict))
    top_rating_dict = sorted(ratings_dict.items(),
                             key=lambda item: item[1],
                             reverse=True)
    print(top_rating_dict[:3])
    #     top_ratings = sorted(ratings_dict.keys(), reverse= True)
    top_ratings = [x[1] for x in top_rating_dict]
    print(top_ratings[:3])
    #     top_teams = [ratings_dict[x] for x in top_ratings]
    top_teams = [team_names[x[0]] for x in top_rating_dict]
    print(len(top_teams))
    print(top_teams[:3])
    #########################################
    return top_teams, top_ratings
Exemplo n.º 5
0
def team_rating(resultfile = 'ncaa_results.csv', 
                teamfile='ncaa_teams.txt',
                K=16.):
    ''' 
        Rate the teams based upon the game results imported from a CSV file.
        (1) import the W matrix from `resultfile` file.
        (2) compute Elo ratings of all the teams
        (3) return a list of team names sorted by descending order of Elo ratings 

        Input: 
                resultfile: the csv filename for the game result matrix, a string.
                teamfile: the text filename for the team names, a string.
                K: a float scalar value, which is the k-factor of Elo rating system

        Output: 
                top_teams: the list of team names in descending order of their Elo ratings, a python list of string values, such as ['Randolph Col', 'Liberty', ... ].
                top_ratings: the list of elo ratings in descending order, a python list of float values, such as ['600.', '500.','300.'].
        
    '''
    #########################################
    ## INSERT YOUR CODE HERE
    top_teams= []
    top_ratings= []
    # load team names from 'teamfile'
    allTeams = import_team_names(teamfile)
    # load game results from 'resultfile'
    allResults = import_W(resultfile)
    totalTeams = len(allTeams)    
    # compute Elo rating of all the teams
    allElos = elo_rating(allResults, totalTeams, K= 16.)
    # sort team names according to their Elo ratings 
    allData = np.vstack((allElos, allTeams)).T.tolist()
    #print(allData)
    #sortAllData = sorted(allData, key=itemgetter(0), reverse=True)
    sortAllData = sorted(allData, key=lambda x: x[0], reverse=True)   
    print(sortAllData)

    
    for i, team in enumerate(allTeams):
        top_teams.append(sortAllData[i][1])
   
    for i, result in enumerate(allElos):
       top_ratings.append(float(sortAllData[i][0]))

    #print(top_teams)
    #print(top_ratings)
    #########################################
    return top_teams, top_ratings
Exemplo n.º 6
0
def team_rating(resultfile = 'ncaa_results.csv', 
                teamfile='ncaa_teams.txt',
                K=16.):
    ''' 
        Rate the teams based upon the game results imported from a CSV file.
        (1) import the W matrix from `resultfile` file.
        (2) compute Elo ratings of all the teams
        (3) return a list of team names sorted by descending order of Elo ratings 

        Input: 
                resultfile: the csv filename for the game result matrix, a string.
                teamfile: the text filename for the team names, a string.
                K: a float scalar value, which is the k-factor of Elo rating system

        Output: 
                top_teams: the list of team names in descending order of their Elo ratings, a python list of string values, such as ['Randolph Col', 'Liberty', ... ].
                top_ratings: the list of elo ratings in descending order, a python list of float values, such as ['600.', '500.','300.'].
        
    '''
    #########################################
    ## INSERT YOUR CODE HERE

    # load team names from 'teamfile'
    team_names = import_team_names(teamfile)

    # load game results from 'resultfile'
    fr = import_W(resultfile)
    results = fr.astype(int)

    # compute Elo rating of all the teams
    elo = elo_rating(results, len(team_names), K)

    # sort team names according to their Elo ratings 

    sorted_teams = np.flip(np.argsort(elo))

    top_teams = []
    for x in sorted_teams:
        top_teams.append(team_names[x])

    top_ratings = np.flip(np.sort(elo))
    print(top_ratings)


    #########################################
    return top_teams, top_ratings
Exemplo n.º 7
0
def team_rating(resultfile='ncaa_results.csv',
                teamfile='ncaa_teams.txt',
                K=16.):
    '''
        Rate the teams in the game results imported from a CSV file.
        (1) import the W matrix from `resultfile` file.
        (2) compute Elo ratings of all the teams
        (3) return a list of team names sorted by descending order of Elo ratings

        Input:
                resultfile: the csv filename for the game result matrix, a string.
                teamfile: the text filename for the team names, a string.
                K: a float scalar value, which is the k-factor of Elo rating system

        Output:
                top_teams: the list of team names in descending order of their Elo ratings, a python list of string values, such as ['team a', 'team b','team c'].
                top_ratings: the list of elo ratings in descending order, a python list of float values, such as ['600.', '500.','300.'].

    '''
    #########################################
    ## INSERT YOUR CODE HERE

    # load game results
    W = import_W(resultfile)

    # load team names
    team_names = import_team_names(teamfile)

    # number of teams
    n_player = len(set(team_names))

    # compute Elo rating of the teams
    team_ratings = elo_rating(W, n_player)

    team_info = zip(team_names, team_ratings)

    # sort team names

    team_info = sorted(team_info, key=lambda x: x[1], reverse=True)

    top_teams, top_ratings = map(list, zip(*team_info))

    #########################################
    return top_teams, top_ratings
Exemplo n.º 8
0
def team_rating(resultfile='ncaa_results.csv',
                teamfile='ncaa_teams.txt',
                K=16.):
    ''' 
        Rate the teams based upon the game results imported from a CSV file.
        (1) import the W matrix from `resultfile` file.
        (2) compute Elo ratings of all the teams
        (3) return a list of team names sorted by descending order of Elo ratings 

        Input: 
                resultfile: the csv filename for the game result matrix, a string.
                teamfile: the text filename for the team names, a string.
                K: a float scalar value, which is the k-factor of Elo rating system

        Output: 
                top_teams: the list of team names in descending order of their Elo ratings, a python list of string values, such as ['Randolph Col', 'Liberty', ... ].
                top_ratings: the list of elo ratings in descending order, a python list of float values, such as ['600.', '500.','300.'].
        
    '''
    #########################################
    ## INSERT YOUR CODE HERE

    # load team names from 'teamfile'
    team_names = import_team_names(teamfile)

    # load game results from 'resultfile'
    W = import_W(resultfile)
    n_players = np.size(team_names, 0)

    # compute Elo rating of all the teams
    R = elo_rating(W, n_players, K)

    # sort team names according to their Elo ratings
    zip_list = list(zip(R, team_names))
    zip_list.sort(reverse=True)
    top_ratings, top_teams = zip(*zip_list)

    #########################################
    return top_teams, top_ratings
Exemplo n.º 9
0
def team_rating(resultfile='ncaa_results.csv',
                teamfile='ncaa_teams.txt',
                K=16.):
    ''' 
        Rate the teams based upon the game results imported from a CSV file.
        (1) import the W matrix from `resultfile` file.
        (2) compute Elo ratings of all the teams
        (3) return a list of team names sorted by descending order of Elo ratings 

        Input: 
                resultfile: the csv filename for the game result matrix, a string.
                teamfile: the text filename for the team names, a string.
                K: a float scalar value, which is the k-factor of Elo rating system

        Output: 
                top_teams: the list of team names in descending order of their Elo ratings, a python list of string values, such as ['Randolph Col', 'Liberty', ... ].
                top_ratings: the list of elo ratings in descending order, a python list of float values, such as ['600.', '500.','300.'].
        
    '''
    #########################################
    ## INSERT YOUR CODE HERE

    # load team names from 'teamfile'
    team_name = import_team_names(teamfile)

    # load game results from 'resultfile'
    results = import_W(resultfile)

    # compute Elo rating of all the teams
    e = elo_rating(results, len(team_name), K=16.)

    # sort team names according to their Elo ratings
    top_set = zip(team_name, e)
    top_set1 = sorted(top_set, key=lambda x: x[1], reverse=True)
    top_teams, top_ratings = map(list, zip(*top_set1))

    #########################################
    return top_teams, top_ratings
Exemplo n.º 10
0
    team_names = []
    with open(filename) as f:
        line = f.readline()

        while line:
            line = line.strip('\n')
            team_names.append(line)
            line = f.readline()
        f.close()
    return team_names


# load game results
W = import_W(filename='ncaa_results.csv')
# load team names
team_names = import_team_names(filename='ncaa_teams.txt')
# number of teams
n_player = len(team_names)
# compute Elo rating of the teams
R = elo_rating(W, n_player, K=16.)

top_ratings = sorted(R,reverse=True)
print n_player
print R
print top_ratings

top = sorted(range(len(R)), key=lambda k: R[k],reverse=True)
top_teams = []
for i in top:
    top_teams.append(team_names[i])
print top_teams