Sitemap

Analyzing Chess Rankings for Top 50 Grandmasters in Google Sheets Using Chess.com API

4 min readMay 16, 2022

--

For a recent data project for my consulting company, Click Analytics, I was tasked with understanding Chess rankings to accomplish 3 major tasks: (1) build a regression model to predict the ranking of a 1000 score players, (2) track player ratings across major ratings agencies, and (3) understand a player’s ranking in different chess formats.

Initially, I was aiming to replicate a chess rating comparison — as seen on this site:

Connecting to Chess Data Sources:

There are 3 chess data sources I used for this project: the chess.com API, the Lichess API, and the UCSF. I constructed an API call for chess.com directly in the Google sheet using JavaScript. I was able to pull the ratings of the top 50 chess players easily. Next, I installed a Python package for the Lichess API using Python and copy pasted the code to the Google sheet. A sample of the sheet can be seen below.

Top 50 Grandmaster Chess Ratings from 3 Data Sources

Chess.com API:

The code to write in the backend of the Google sheet was fairly straightforward using JavaScript code. The GET request looks like this:

API Call in JavaScript

function chess_api_rapid() {

var response = UrlFetchApp.fetch(“https://api.chess.com/pub/leaderboards")

var json_response = JSON.parse(response);

var ss = SpreadsheetApp.getActiveSpreadsheet();

var chest_score_sheet = ss.getSheetByName(‘ChessData’);

var username;

var score;

console.log(json_response.live_rapid)

for(var i=0; i<json_response.live_rapid.length; i++){

username = json_response.live_rapid[i].username

score = json_response.live_rapid[i].score

console.log(username);

var row = 3 + i

var usernameNameCell = `A${row}`

console.log(“Username Cell: “, usernameNameCell)

var cellToWrite = `B${row}`

console.log(cellToWrite);

chest_score_sheet.getRange(usernameNameCell).setValue(username);

chest_score_sheet.getRange(cellToWrite).setValue(score);

}}

I can then loop through the response and get the rating for any player with any format.

The response for that looks like this:

Lichess API:

The Lichess API has a package built using PIP. For a list of players, it is straightforward to get the user information:

user = lichess.api.user(i)

UCSF Data Download:

The UCSF data can be downloaded directly from their website.

Trouble with getting ratings for each player on each site:

The Lichess API has disabled ratings for many of these chess players so it is not possible to get the ratings for every player across Chess.com and Lichess. Further complicating matters, the UCSF

http://www.uschess.org/component/option,com_top_players/Itemid,371/

Analyzing Mr. Dubov:

Daniil Dubov is a Russian chess prodigy. He became a grandmaster at the age of 14.

Daniil Dubov

We can also again use the Chess.com API to live pull the data into the dashboard which looks like this:

Dubov Rating

Lessons Learned:

  • Problem of consistent data across data sources
  • Necessity to corral specific chess ratins
  • Lots of rich data when looking at chess

Next Steps:

The Chess dashboard can be used to analyze more fine-tuned questions such as which chess player is improving the fastest and which chess players lead the chess world in frequency of matches and success (W/L).

We Can Also Make a Logistic Regression Equation to Predict Player Rating:

A logistic curve fits data with a non-linear fit.

Logistic Regression Graph

I will plot 2 ratings at a time. On the X-axis, plot the Chess.com ratings and on the Y-axis plot the Lichess API ratings. If the ratings on each platform are identical, then we would see a linear pattern on the graph of the two rating types.

However:

The ratings are not identical. The Logistic Regression equation:

Logistic Regression Equation

In this equation, we have several operations:

The denominator, represented by

1 + e^-(x-mu)/s.

The data ultimately would rather fall in to a loose linear model.

Making Precise Predictions:

Once robust enough, with the maximum set of chess rating data, one can build models.

--

--

Basil Latif
Basil Latif

Written by Basil Latif

Data Scientist — 1,000,000,000+ data points processed

No responses yet