{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Lesson 1: Explaining xT\n\nThis is an example lesson, which is copied from this excellent\n[blog post](https://soccermatics.medium.com/explaining-expected-threat-cbc775d97935) by\n[David Sumpter (@soccermatics)](https://twitter.com/Soccermatics). I have\ndispersed some random python code inbetween to demonstrate how Sphinx gallery\ncan be used to generate examples.\n\nOne of the key questions for everyone interested in football \u2014 \nfrom coaches, through scouts to the fans \u2014 \nis how do we assess the quality of a player using data.\nIf they score a lot of goals they must be good and, more recently,\nwe have understood that finding good scoring opportunities\n(having high xG) is also good. But what about all those passes,\ndribbles, blocks and interceptions. How do we value them?\n\nSome inline math $s_{x,y}$ for the probability of shooting at position\nx y and the full formula for expected threat\nfrom [Karun's blog](https://karun.in/blog/expected-threat.html)\n\n\\begin{align}\\texttt{xT}_{x,y} = (s_{x,y} \\times g_{x,y}) + (m_{x,y} \\times \\sum_{z=1}^{16} \\sum_{w=1}^{12} T_{(x,y)\\rightarrow(z,w)}\\texttt{xT}_{z,w})\\end{align}\n\nIt is with this in mind that\n[The Athletic](https://theathletic.com/2751525/2021/08/06/introducing-expected-threat-or-xt-the-new-metric-on-the-block/)\nhave started using expected threat when talking about player and team performance.\nThe idea is to assign a value to every point on the football field based on the probability\nthat having the ball at that point will lead to a goal. One example of these probability maps is shown below.\n\n<img src=\"file://../../../lessons/lesson1/twelve_xt.png\">\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Markov chains\nIn order to evaluate actions we look at how an action changes the probability of scoring.\nIt is this change in probability of scoring which is the expected threat (xT).\nIf a player makes a pass which moves the ball from a place where it is unlikely\nfor their team to score, to a place where they are more likely to score,\nthen they have increased the xT in favour of their team. In general,\nthe nearer you get the ball to the goal the more likely your team is to\nscore (although if you look carefully passes back to the goalkeeper are also valuable).\n\nMore details of how expected threat is calculated can be found \nin Friends of Tracking in this video.\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "..  youtube:: 0VAdzaid8L8\n   :width: 375\n   :height: 210\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Expected threat history\nExpected Threat was invented by Sarah Rudd in 2011. She didn\u2019t call it that.\nIn fact, she didn\u2019t call it anything, but she had the mathematical insight,\nusing Markov chains, on which it is based. In this video you can see her go\nthrough all the steps. And, on that basis she was recruited to StatDNA,\nwho were very soon after bought up by Arsenal.\nThe name xT was first used by Karun Singh, who reproposed it in\nthe public sphere in a blog post in 2018.\n\nIt is extra important that when we have a clear example of an idea from a\nfemale scientist in a male-dominated area, which is now used everywhere,\nthat we pause to make sure everyone knows where it came from.\nThere is a history of womens\u2019 contributions being forgotten in Science.\nIt would be embarrassing if we made this same error in the so-called modern\nera, especially in football.\n\nSo when we hear about how Liverpool used expected goals added\n(yes, that is expected threat) in recruitment during 2018\u201319\nor we about how Opta and Statsbomb have there own version of expected\nthreat, remember that all this came from the work of one very determined\nyoung woman, more than ten years ago, who went to as many sports\nanalytics conferences as she could and pestered everyone she met\nuntil she got one of the first ever jobs in football analytics.\n\n(I wrote about Sarah Rudd in Soccermatics\nand I have booked in her in for a Friends of Tracking video during the autumn,\nso there will be a chance to hear more about her story soon)\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, ax = plt.subplots()\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.10.5"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}