{"cells":[{"metadata":{},"cell_type":"markdown","source":"# **NCAA March Madness Analytics**\n\n### **Introduction**\n\nThe NCCA men basketball tournament, more commonly known as March Madness is, until this year, a classic annual event that captures the attention of basketball fans and non-basketball fans.  Office pools, Warren Buffet’s multimillion-dollar bracket, rooting for your alma mater or favorite team, and Kaggle’s Machine Learning Mania make it a fun time of year.  The tournament consists of 68 teams that have either won their respective conference championship or were selected by a committee of experts.   The committee seeds and assigns each team to one of four regions. When play begins it is either win or go home.   At the end of tournament, one team goes home undefeated.\n\n### **Data**\n\nData used for the study was provided by Kaggle’s Google Cloud & NCAA March Madness Analytics competition.\n\n* Play by play data for the 2015 through the 2019 season.\n* Regular season detailed results, subset to the play by play seasons\n* Tournament seeds, subset to the play by play seasons.\n* Teams names data set.\n* Team conferences data set.\n* \nThe games being reviewed are selected from two sources, a sporting news article by Mike Decourcy [1].  Ranking of the best games from the NCAA Tournament and one of my personal.   \n\n\n### **Analysis Method**\n\nFor the selected games, \n\n* Regression analysis is used to compare each team’s regular season expected points for and points against vs time against the tournament game.  \n* The Poisson distribution is used to calculate the probability for rates of blocks, steals, turnovers, and points for a given time period in each game.\n* Plot the score difference between the two teams along with the cumulative sums of steals, blocks, turnovers vs. game time to visually locate the changes in rates, that indicate time spans to focus on.\n* Games that the play by play data has x and z coordinates shot charts to assess team strategy.\n\n### **The Games.**\n\n* **“Heart Break Comeback”**: 2016, Northern Iowa vs. Texas A&M.  A&M goes on a 12-point run to send the game into overtime in the last 44 seconds of regulation.\n* **“Cinderella Upset”:**  2018, Virginia’s loss to UMBC.  This was the first time ever that a number one seed lost to a number 16 seed.\n* **“Teams Always Defeat Individuals”:**  2019, Michigan State vs. Duke, Zion Williamson and Duke were expected roll.\n\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"# Load Packages\n\nlibrary(data.table)\nlibrary(tidyverse)\nlibrary(grid)\nlibrary(gridExtra)\nlibrary(ggplotify)\nlibrary(gtable) \nlibrary(dplyr)\n\n# Path to data and play by play data\npath <- c(\"../input/march-madness-analytics-2020/MDataFiles_Stage2/\")\npath_play <- c(\"../input/march-madness-analytics-2020/MPlayByPlay_Stage2/\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"options(warn=-1) # turn off warning messages","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Load source code for ploting the basketball court\n\nsource(\"../usr/lib/court_plot/court_plot.R\")\nsource(\"../usr/lib/ncaa_madness/ncaa_madness.R\")\nsource(\"../usr/lib/ncaa_functions/ncaa_functions.R\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Load Data\n\nregresults <- fread(paste0(path,\"MRegularSeasonDetailedResults.csv\"))\nresults <- fread(paste0(path,\"MNCAATourneyDetailedResults.csv\"))\nseeds <- fread(paste0(path,\"MNCAATourneySeeds.csv\"))\nteams <- fread(paste0(path, \"MTeams.csv\"))\nconf <- fread(paste0(path, \"MTeamConferences.csv\"))\nseeds$Seed = as.numeric(substring(seeds$Seed,2,3))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"options(repr.plot.width = 10, repr.plot.height = 8)\nplotgame(WTeam = \"Texas A&M\" ,LTeam = \"Northern Iowa\", 2016)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Figure 1.\n\nFigure one, shows the elapsed time vs. score.  Northern Iowa, from the MVC conference, has a comfortable lead on Texas A&M of the SEC.  With time running out in the second half; Northern Iowa makes a free throw to go up by 12 points with 44 seconds left in the second half.  Then, Texas A&M scores 12 point in 44 seconds to send the game into overtime.  In the end, Texas A&M won the game, a heart breaker for Northern Iowa.  \nAt the end of the second half: \n* How probable was Texas A&M’s run at the second half? or did Northern Iowa go cold?\n* Toward the end of games, teams can sacrifice scoring and focus on letting the clock run out.  Was this the case for Northern Iowa?\n* What about the middle of the first half?  Texas A&M struggled to score, how probable was this?\n\nFigure 2, adds the regression lines for each teams’ regular season points for and points against."},{"metadata":{"trusted":true},"cell_type":"code","source":"options(repr.plot.width = 10, repr.plot.height = 8)\nplotRegressComp(WTeam = \"Texas A&M\" ,LTeam = \"Northern Iowa\", 2016)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Figure 2.\n\nAt the end second half and the end of the game both teams are close to their expected point totals, Texas A&M scored 92 point, and was expected to score 93, and Northern Iowa was expected to score 85 point and scored 88 points.  Two time periods stand out.  \n* Mid way through the first half, Texas A&M made two shots for a total of 5 points over a 10 minute 30 second time span.  \n* Both teams return to scoring close to the slope of the regression line.  Then, the last 44 seconds of the 2nd half is what made this game a classic.  \n\nFigure 3, looks each at team’s score difference and the cumulative sum of blocks, steals, and turnovers between 780 – 1410 seconds of the game.\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"options(repr.plot.width = 12, repr.plot.height = 8)\nplotgameEventsTime(WTeam = \"Texas A&M\" ,LTeam = \"Northern Iowa\", 2016,tstart = 780, tend = 1410, maxdiff = 25,mindiff = -20)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Figure 3. \n\nFigure 3, does not show a rapid change in blocks, steals, or turnover.  Figure 2, shows that Texas A&M’s simply did not score points in this time span, while Northern Iowa continued to score at their expected rate.  From the regular season data and the game data between 780 – 1410 seconds, the probability of Texas A&M making 2 or less points after attempting 16 shots is 0.000676.  A rare event.\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"options(repr.plot.width = 12, repr.plot.height = 8)\nplotgameEventsTime(WTeam = \"Texas A&M\" ,LTeam = \"Northern Iowa\", 2016,tstart = 2350, tend = 2400, maxdiff = 25,mindiff = -20)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Figure 4.\n\nFigure 4, shows Texas A&M between 2350 – 2400 seconds:\n* Stole the ball three times.\n* Scored 14 points.\nThe probability of scoring 14 or more points in 50 seconds, is 0.001.  Figure 5, uses the regular season data to calculate events per second, lambda, to see how likely stealing the ball three times in 50 seconds was.\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"options(repr.plot.width = 12, repr.plot.height = 10)\npoisPlotProb(WTeam = \"Texas A&M\" , LTeam = \"Northern Iowa\", year = 2016, tstart = 2350, tend = 2400,\n             Block = 0, Steal = 3, Turnover = 3,maxEvent = 10) ","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Figure 5.\n\nSummary, the probability of the 3 steals is almost zero. \n\nSummary, three improbable events lead to this game’s “madness”\n* Texas A&M’s making two baskets in a 10 minute 30 seconds.\n* Texas A&M’s three steels in 50 seconds.\n* Texas A&M making 7 baskets for 14 points in 50 seconds to force overtime."},{"metadata":{"trusted":true},"cell_type":"code","source":"options(repr.plot.width = 10, repr.plot.height = 8)\nplotgame(WTeam = \"UMBC\" ,LTeam = \"Virginia\", 2018)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Figure 6.\n\nIn the history of the tournament, a number one seed was defeated by a number 16 seed one time.  The 2018 Virginia vs. UMBC was that game.  UMBC? University of Maryland, Baltimore County.  UMBC, not only won, they won by 20 points.  Figure 6, starts to tell the story.  \n"},{"metadata":{"trusted":true},"cell_type":"code","source":"options(repr.plot.width = 10, repr.plot.height = 8)\nplotRegressComp(WTeam = \"UMBC\" ,LTeam = \"Virginia\", 2018)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Figure 7.\n\nAdding in the regression lines, Figure 7 shows the following:\n* Both teams start the game underperforming on offense. \n* Virginia underperformed on both offense and defense for the entire game.\n* The 2nd half that UMBC slowly returns to their expected scoring rate, ending within one point of their expected points scored. \n* UMBC overperformed on defense.  Virginia scored 54 vs. UMBC’s expected points against of 61 points.  "},{"metadata":{"trusted":true},"cell_type":"code","source":"options(repr.plot.width = 12, repr.plot.height = 8)\nplotgameEventsTime(WTeam = \"UMBC\" ,LTeam = \"Virginia\", 2018,tstart = 2000, tend = 2400, maxdiff = 25,mindiff = -20)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Figure 8,\n\nFigure 8, highlight the last 400 seconds of the game.  UMBC makes 11 shots, for a field goal percentage of 68.8%, and scores 20 points.  Compared to UMBC’s regular season field goal percentage of 43.8%, this late game shooting percentage was unlikely.  Regardless, a great UMBC game, for Virginia, shocking.  highlight the last 400 seconds of the game.  UMBC makes 11 shots, for a field goal percentage of 68.8%, and scores 20 points.  Compared to UMBC’s regular season field goal percentage of 43.8%, this late game shooting percentage was unlikely.  Regardless, a great UMBC game, for Virginia, shocking. "},{"metadata":{"trusted":true},"cell_type":"code","source":"options(repr.plot.width = 10, repr.plot.height = 8)\nplotgame(WTeam = \"Michigan St\",LTeam = \"Duke\",2019)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Figure 9.\n\nThis was a highly anticipated game.  The 2019 Duke, a number one seed, was a power house, featuring Zion Williamson, against a classic Michigan State team.  Michigan State seems to start each season by losing a few games.  As the season goes on, they steadily improve.  By the NCAA tournament, they seem to peak.  2019 they are a number two seed. Duke is favored by many experts to make the final four.[2]\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"options(repr.plot.width = 10, repr.plot.height = 8)\nplotRegressComp(WTeam =\"Michigan St\",LTeam =\"Duke\",2019)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Figure 10.\n\nFigure 10, add the regression lines.  The game is back and forth.  Neither team hits their expected points for, but are tracking closer to their respective points against.  Toward the end of the 1st half, Duke goes flat."},{"metadata":{"trusted":true},"cell_type":"code","source":"options(repr.plot.width = 12, repr.plot.height = 8)\nplotgameEventsTime(WTeam =\"Michigan St\",LTeam =\"Duke\",2019,tstart = 875, tend = 1300, maxdiff = 25,mindiff = -20)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Figure 11.\n\nFigure 11.  highlight that Duke made two shots on 11 attempts in 7 minutes.  Probability of two or less in this time period 4.5% comparted to 47.7% during the regular season."},{"metadata":{},"cell_type":"markdown","source":"This game contains coordinate data for the game events.  The shot chart in Figure 12 highlights the following:\n* Duke had 82 shot attempt and Michigan State 86.\n* Duke’s shooting percentage was better than Michigan State.\n* Duke focused on shooting three-point shots and points in the paint.\n* Michigan State focus on containing Williamson, he shot 34% from the field. [3]\n* Both teams made six three-point shots, but Duke visually attempted more three-point shots.\n* In the end, Michigan state shot and made more two-point shots, and holding Duke to two points in seven minutes was the difference.\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"options(repr.plot.width = 12, repr.plot.height = 10)\nshotChart(\"Michigan St\",\"Duke\",2019)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Figure 12."},{"metadata":{},"cell_type":"markdown","source":"References:\n\n* [1] https://www.sportingnews.com/us/ncaa-basketball/news/march-madness-ranking-best-games-ncaa-tournament-history-mike-decourcy/1lvr64uzdayks1e68oy8yqzvv1\n* [2] https://www.businessinsider.com/expert-picks-march-madness-final-four-2019-2019-3\n* [3] https://www.sbnation.com/college-basketball/2019/4/1/18290155/zion-williamson-stats-duke-michigan-state-ncaa-tournament-2019-march-madness\n* [4] https://math.stackexchange.com/questions/151810/probability-of-3-heads-in-10-coin-flips\n* [5] “Analyzing Baseball Data with R”, Max Marchi Jim Albert.\n* [6] https://toddwschneider.com/posts/nba-vs-ncaa-basketball-shooting-performance/\n* [7] https://en.wikipedia.org/wiki/Basketball_court\n"}],"metadata":{"kernelspec":{"display_name":"R","language":"R","name":"ir"},"language_info":{"mimetype":"text/x-r-source","name":"R","pygments_lexer":"r","version":"3.4.2","file_extension":".r","codemirror_mode":"r"}},"nbformat":4,"nbformat_minor":4}