Monday, May 30th, 2011...3:19 pm
A bit of data to mine
Increasingly, I’ve been asked about my work with Amy Langville in sports ranking. In particular, students and faculty have been interested in researching or teaching ranking methods based in linear algebra. To help enable others tailor their work, I inevitably discuss how to find sports data. One of the easiest ways to explore existing methods is to apply them to online datasets. In this blog entry, I’ll explain how to access data that would enable one to rank the almost 350 Division I Men’s Basketball Teams. We’ve used such data to create math-generated brackets for March Madness.
Our task in sports ranking is straight forward. We need data. From this data, we rank the teams. We’ll see how to access season data for every game played by NCAA Division I Men’s basketball teams.
First, let’s understand how to interpret the data. One file will contain information on each game during the season. Each row of the file corresponds to a game and the columns contain the following data:
- column 1 = date of game as measured as days since 1/1/0000
- column 2 = date in YYYYMMDD format
- column 3 = team 1 index
- column 4 = team 1 score
- column 5 = team 1 home field (1 = home, -1 = away, 0 = neutral)
- column 6 = team 2 index
- column 7 = team 2 score
- column 8 = team 2 home field (1 = home, -1 = away, 0 = neutral)
For example, here are a few rows from games played in 2008.
733721, 20081110, 98, 65, 0, 114, 63, 0,
733721, 20081110, 75, 80, 1, 228, 49, -1,
733722, 20081111, 206, 73, 0, 128, 60, 0,
733722, 20081111, 114, 76, 0, 228, 57, 0,
We see from this data that on November 10, 2008 team 98 beat team 114 by the score of 64-63 on a neutral court. Also on that day, team 75 beat team 228 at home by a score 80-49. You should be able to read the remaining two rows of data extracted from the dataset.
Who’s who? Another data file indicates the correspondence between the natural numbers and teams. The first few rows again from 2008 are:
1, Air_Force
2, Akron
3, Alabama
4, Alabama_A&M
5, Alabama_St
6, Albany_NY
7, Alcorn_St
8, American_Univ
9, Appalachian_St
Now, we only need to download such datasets. Let’s download the data for the 2010-11 season. Here are the steps:
- Visit http://www.masseyratings.com/data.php.
- Scroll to the bottom and select Basketball > College Basketball > 2011
- Click the cb2011 link at the top of the web page.
- Navigate to NCAA > NCAA I > Scores
- Visit the All link.
- To download the game data, select the Intra and Matlab Games
- To download the team data, select the Intra and Matlab Teams
Clearly, the data is Matlab-ready. Loading the games is quite easy. Here is the Matlab code I use:
fid = fopen(gameFilename);
gameData=load(gameFilename);
numberOfGames = size(gameData, 1);
Now, we have a matrix gameData that has each column of our
input file as a column in our matrix. So the input file:
733721, 20081110, 98, 65, 0, 114, 63, 0,
733721, 20081110, 75, 80, 1, 228, 49, -1,
733722, 20081111, 206, 73, 0, 128, 60, 0,
733722, 20081111, 114, 76, 0, 228, 57, 0,
becomes the matrix
Loading the team names is a bit more involved. Here is the code I use:
fid = fopen(teamFilename);
counter = 0;
while (ischar(teamname))
counter = counter + 1;
[token, remain] = strtok(teamname);
teamname = strtok(remain);
teamname=cellstr(teamname);
teamNames(counter) = teamname;
teamname = fgetl(fid);
end
fclose(fid);
numTeams = counter;
That’s it! Interested in another sport? Search around the Massey site and see what you find. If you can’t find it there, look around the Internet as you may find useful data elsewhere. Happy ranking!
