Skip to content
Live Tennis API Free API key ↗
Menu
Classroom exercise

What predicts a tennis match?

A single lesson for a data or programming class, with no account and no key. Students use a free synthetic data generator and a free win probability calculator to answer one question: what predicts a tennis match? They test a ranking against the result, then a serve number, and see which one carries information. It fits one hour and needs a browser and a little arithmetic.

Open the data generatorOpen the calculator

What do students learn?

By the end of the hour a student can test whether one column predicts an outcome. They read that result against the spread a small sample gives. Then they turn a serve number into a win chance. The wider lesson is the difference between a label and a mechanism.

What do students need?

A browser and either a spreadsheet or a few lines of code. No account, no key and no card. Both tools are free to open. The one live call in the lesson is a health check that needs no key.

GET https://api.livetennisapi.com/api/public/v1/health
{"status": "ok", "version": "v1"}

Part one: does the ranking pick the winner?

The generator plays seeded synthetic matches in the shape of a real match record. Each record carries two players with a ranking, and the winner. Nothing in it is real, and every record is flagged as synthetic.

  1. Check the API is up Run the health call shown under what you need. It needs no key and answers in one line, so the class knows the live service is reachable.
  2. Make the data Open the generator with the seed and count below. Every student gets the same matches, so the room can compare answers. Download the set as CSV.
  3. Find the favourite In each match the favourite is the player with the smaller ranking number. Read the two ranking columns and the winner column. Leave out any match where the two players share a ranking number.
  4. Count and divide Count the matches the favourite won. Divide by the number of matches you counted to get the favourite rate.

Use the seed classroom and 50 matches, so the whole class works on the same set:

https://livetennisapi.com/tools/mock-tennis-data?seed=classroom&count=50

The favourite rate is a plain fraction.

favourite rate = favourites who won / matches counted

Worked answer. On this set every match has two different rankings, so all 50 count. The favourite won 27 of 50, which is 54%. The generator draws each player's ranking at random from 1 to 500, with no tie to how the match is played. So the ranking should not predict the winner, and the rate sits near an even split. With fifty matches the rate scatters about seven points either way by chance. A figure in the forties or fifties is noise, not a signal.

Part two: what does decide a match?

The calculator uses the standard model for this question. Every point is independent, and each player wins a point on their own serve with one fixed chance. From that one number per player it works out a game, a set and a match by exact steps.

  1. Open the calculator Enter the two serve numbers below, pick best of three and a final-set tie-break to seven. The address carries your numbers, so a link shares a result.
  2. Read the rows Note the chance each player holds serve, wins a set and wins the match. Write down player A's match chance.
  3. Check one figure Work out A's hold by hand or in code from the formula below, then match it against the hold row. They should agree to the first decimal.
  4. Try the control Set both serve numbers equal and read the match chance again. Equal serve numbers give an even match, whatever the rest of the lesson suggested.

Enter player A on 66% of serve points and player B on 60%:

https://livetennisapi.com/tools/win-probability?a=66&b=60&sets=3&final=7

In the hold formula below, p is the chance the server wins a point and q is the chance the server loses it.

hold = p^4 * (15 - 4p - 10p^2 / (1 - 2pq))

Worked answer. Player A on 66% of serve points holds 84.6% of service games, and player B on 60% holds 73.6%. Player A wins a set 69.3% of the time and a best of three match 77.5% of the time. Set both numbers to 65% and the match falls to 50%. A real six-point edge on serve moves the match a long way from even. The ranking in part one did not. That is the point of the lesson.

The calculator's method section walks through each step, and the page offers the same model as a spreadsheet of formulas.

Where does a real serve number come from?

Part two used numbers the class chose. For a real match the number is service points won, the points a player wins while serving as a share of the points they serve. The Live Tennis API reports it per match as service_points_won_pct in the match statistics, which is part of the paid plans. That figure sums up a finished match, so it looks back at what happened. A real prediction needs a serve estimate from before the match, which is a harder problem.

A class that wants real data on the free plan can take the next step with live scores instead. The coding exercises for teachers call live and upcoming matches and scores, which the free plan covers. Each student gets their own free key with no card.

How do I grade it?

Out of 10 points, for a short piece of class work. Change the weights to suit your course.

The rubric, out of 10 points
PartPointsFull marks when
Part one4The favourite rate is counted correctly and written as a percentage.
Part two3The three calculator figures are read correctly and one hold is checked by hand.
The point3The write-up explains why the ranking rate sits near an even split and the serve edge does not, and mentions the sample size.

There is no single right favourite rate. The exact figure depends on the seed, so the reasoning earns the marks, not the number.

What comes next?

For a longer project, the capstone brief asks whether the score predicts the match on a real sample, with milestones and a rubric. The coding exercises for teachers cover requests, scores and rate limits in Python and JavaScript.

Teaching with this exercise? We would like to hear how it went. Email hello@livetennisapi.com. We never publish anything about a class without the teacher's consent.