nfl定理

NFL 2020 season is coming soon. For preview this season, I’m going to visualize some quarterbacks data using 2019 dataset.

NFL 2020赛季即将到来。 为了预览本季,我将使用2019年数据集可视化一些四分卫数据。

1.概述 (1. Overview)

In this article, I’m going to use this dataset as below. Thanks to Mr. Ron Yurko.

在本文中,我将使用以下数据集。 感谢Ron Yurko先生。

There is play-by-play dataset of pre-season, regular season and play-off. I’m going to use only regular season and visualize every team defensive stats, especially pass defense and run defense. This is brief visualization so please note that not kind of analysis and deeping dive.

有季前,常规赛和附加赛的逐项比赛数据集。 我将只使用常规赛季,并可视化每支球队的防守数据,尤其是传球和防守。 这是简短的可视化,因此请注意,这不是一种分析和深入探讨。

Let’s get down to implementation.

让我们开始实施。

About offense, I did about quarterback and rusher with individual stats. Please see also these article.

关于进攻,我用个人数据处理了四分卫和冲刺。 请参阅这些文章。

2.预处理 (2. Preprocess)

import pandas as pdpd.set_option(“max_columns”, 400)pbp = pd.read_csv(“play_by_play_data/regular_season/reg_pbp_2019.csv”)games = pd.read_csv("games_data/regular_season/reg_games_2019.csv")

Firstly, narrow down the columns which is needed for passing defense.

首先,缩小通过防御所需要的范围。

pbp_passing = pbp[  [    "game_id"    ,"game_half"    ,"qtr"    ,"defteam"    ,"down"    ,"two_point_attempt"    ,"yards_gained"    ,"play_type"    ,"first_down_pass"    ,"pass_attempt"    ,"complete_pass"    ,"incomplete_pass"    ,"sack"    ,"touchdown"    ,"interception"    ,"pass_touchdown"    ,"score_differential"  ]]

And then, aggregate this dataset by defense team.

然后,由防御团队汇总此数据集。

#Don't include two point attemptpbp_passing.loc[pbp_passing.two_point_attempt == 1, "yards_gained"] = 0team_def_pass_stats = pbp_passing[  pbp_passing.pass_attempt == 1].groupby(  "defteam"  ,as_index=False).agg(  {    "complete_pass": "sum"    ,"yards_gained": "sum"    ,"first_down_pass": "sum"    ,"pass_touchdown": "sum"    ,"incomplete_pass": "sum"    ,"sack": "sum"    ,"interception": "sum"  })team_def_pass_stats["pass_attempt"] = team_def_pass_stats["complete_pass"] + team_def_pass_stats["incomplete_pass"] + team_def_pass_stats["interception"]team_def_pass_stats["complete_rate"] = round(team_def_pass_stats["complete_pass"] / team_def_pass_stats["pass_attempt"], 3) * 100team_def_pass_stats = team_def_pass_stats_season[  [    "defteam"    ,"pass_attempt"    ,"complete_rate"    ,"yards_gained"    ,"pass_touchdown"    ,"interception"    ,"first_down_pass"    ,"sack"  ]].sort_values("yards_gained").reset_index(drop=True)

On the other hand, I do the same for run defense.

另一方面,我对跑步防守也做同样的事情。

Narrow down columns,

缩小的色谱柱

pbp_rushing = pbp[  [    "game_id"    ,"game_half"    ,"qtr"    ,"down"    ,"two_point_attempt"    ,"defteam"    ,"yards_gained"    ,"play_type"    ,"first_down_rush"    ,"rush_attempt"    ,"touchdown"    ,"rush_touchdown"    ,"score_differential"  ]]

Aggregate by team.

按团队汇总。

team_def_rush_stats = pbp_rushing[  (pbp_rushing.rush_attempt == 1)  & (pbp_rushing.two_point_attempt == 0)].groupby(  "defteam"  ,as_index=False).agg(  {    "rush_attempt": "sum"    ,"yards_gained": "sum"    ,"first_down_rush": "sum"    ,"rush_touchdown": "sum"  }).sort_values("yards_gained").reset_index(drop=True)
team_def_rush_stats_season.head()
team_def_rush_stats_season.head()

I want to use these dataset as one, so merge it. Merge key is “defteam”.

我想将这些数据集用作一个,所以将其合并。 合并键为“ deteam”。

team_defense_stats = pd.merge(  team_def_pass_stats  ,team_def_rush_stats  ,on="defteam"  ,how="inner"  ,suffixes=["_passing", "_rushing"] #If there are same columns, add suffixes)
team_defense_stats
team_defense_stats

In addition to this, I also need opponent points for every team. Extract this data from games dataset.

除此之外,我还需要为每支球队提供对手得分。 从游戏数据集中提取此数据。

home_games = games.groupby("home_team", as_index=False).agg(  {"away_score": "sum"})home_games = home_games.rename(columns={"away_score": "opponent_points"})home_games = home_games.rename(columns={"home_team": "team"})away_games = games.groupby("away_team", as_index=False).agg({"home_score": "sum"})away_games = away_games.rename(columns={"home_score": "opponent_points"})away_games = away_games.rename(columns={"away_team": "team"})team_opponent_points = pd.merge(  home_games  ,away_games  ,on="team"  ,how="inner"  ,suffixes=["_home", "_away"])team_opponent_points["opponent_points"] = team_opponent_points.opponent_points_home + team_opponent_points.opponent_points_away
team_opponent_points.head()
team_opponent_points.head()

In the end, merge defense stats and opponent points dataset.

最后,合并防御统计数据和对手得分数据集。

team_defense_stats = pd.merge(  team_defense_stats  ,team_opponent_points  ,left_on="defteam"  ,right_on="team"  ,how="inner")
team_defense_stats[[“defteam”, “yards_gained_passing”, “yards_gained_rushing”, “opponent_points”]].head()
team_defense_stats [[“ defteam”,“ yards_gained_pa​​ssing”,“ yards_gained_rushing”,“ opponent_points”]]。head()

3.可视化 (3. Visualization)

Let’s plot passing yards and rushing yards as scatter and color each plot depending on opponent points.

让我们绘制散布码和冲码作为散点图,并根据对手的点为每个图着色。

%matplotlib inlineimport matplotlib.pyplot as pltwith plt.rc_context(  {    "axes.edgecolor":"white"    ,"xtick.color":"white"    , "ytick.color":"white"    , "figure.facecolor":"white"  }):  fig = plt.figure(figsize=(30, 24), facecolor="black")  ax = fig.add_subplot(111, facecolor="black")#Plot scatters = ax.scatter(  team_defense_stats.yards_gained_passing  ,team_defense_stats.yards_gained_rushing  ,s=600  ,alpha=0.5  ,c=team_defense_stats.opponent_points  ,cmap="bwr"  ,marker="D")#Adjust lookingax.set_xlabel("Pass Defense (Yds)", color="white", size=24)ax.set_ylabel("Run Defense (Yds)", color="white", size=24)ax.set_xlim(5000, 2500) #less is betterax.set_ylim(2500, 1000) #less is betterax.tick_params(axis="x", labelsize=24)ax.tick_params(axis="y", labelsize=24)#Plot team namefor _, team in team_defense_stats.iterrows():  ax.text(    team.yards_gained_passing    ,team.yards_gained_rushing    ,team.defteam    ,verticalalignment="center"    ,horizontalalignment="center"    ,fontsize=25    ,color="white"  )#Colorbar settingscb = plt.colorbar(s)cb.set_label("Opponent Points (Season)", color="white", size=30)cb.outline.set_edgecolor("white")plt.setp(plt.getp(cb.ax.axes, 'yticklabels'), color="white")plt.title("Team Defensive Stats", color="white", size=30)

Patriots as “NE” is very good at both pass defense and run defense. Bills and Ravens also looks good. 49ers is strong at pass defense. They have less opponent points (blue marker) so we can say they are good as defense!

作为“ NE”的爱国者在传球防守和奔跑防守方面都很擅长。 比尔和乌鸦看起来也不错。 49ers的传球防守能力强。 他们的对手得分(蓝色标记)更少,所以我们可以说他们的防守很好!

On the other hand, Buccaneers is outstanding at run defense but has more opponent points (red marker). Can we say that run defense less valuable than pass defense?

另一方面,海盗在奔跑防守方面表现出色,但对手得分更高(红色标记)。 我们可以说奔跑防守的价值不及传球防守吗?

How is the breakdown of touchdown? Use pie chart.

触地得分如何细分? 使用饼图。

plt.rc_context(  {    "axes.edgecolor":"white"    ,"xtick.color":"white"    , "ytick.color":"white"    , "figure.facecolor":"white"  }):  fig = plt.figure(figsize=(10, 10), facecolor="black")  ax = fig.add_subplot(111, facecolor="black")wedges, _, _ = ax.pie(  [pbp.pass_touchdown.sum(), pbp.rush_touchdown.sum()]  ,labels=["Pass", "Rush"]  ,textprops={    "color": "white"    ,"fontsize": 20  }  ,wedgeprops={"linewidth": 3}  ,startangle=90  ,counterclock=False  ,autopct="%1.1f%%")ax.text(  0, 0  ,str(int(pbp.pass_touchdown.sum() + pbp.rush_touchdown.sum()))  ,color="white"  ,ha="center"  ,va="center"  ,fontsize=40)ax.set_title("Touchdown Ratio", color="white", size=40)plt.setp(wedges, width=0.2)

Could this mean preventing pass touchdown is more valuable than rush touchdown? I don’t think so. Of course passing can gain much more than rushing, so when it comes to scoring or touchdown, passing is likely chosen in the touchdown situation. Therefore, rushing looks less effective to get point numerally. It’s just common sense.

这是否意味着阻止通过触地得分比抢地更有价值? 我不这么认为。 当然,传球比冲刺能获得更多的收益,因此,在得分或触地得分时,在触地得分情况下很可能会选择传球。 因此,冲刺看上去不太有效地获得数字点。 这只是常识。

Take a look about which option, pass or run, is chosen in the touchdown situation.

看看在触地得分情况中选择了通过还是运行选项。

Oh, I said “passing is likely chosen in the touchdown situation” but I wrong. Pass and run is equally chosen. Is Run defense less valuable than pass defense for preventing from opponent points, maybe this is wrong issue and wasting time to answer this. We need deeper dive about defense.

哦,我说过“触地得分情况下很可能会选择通过”,但我错了。 通过和运行是同等选择的。 与防止对手得分相比,奔跑防守的价值不及传球防守的价值,也许这是错误的问题,并且浪费时间来回答这个问题。 我们需要深入研究防御。

By the way, I know you think that how can we plot team logo instead of marker? We can do that using “artist”. To get more details, please check my article.

顺便说一句,我知道您认为我们应该如何绘制团队徽标而不是标记? 我们可以使用“艺术家”来做到这一点。 要获取更多详细信息,请查看我的文章。

Of course, you need to prepare all of team image file in previous. This is much harder than programming ;)

当然,您需要事先准备所有团队形象文件。 这比编程难得多;)

from matplotlib.offsetbox import OffsetImage, AnnotationBboxplt.rc_context(  {    "axes.edgecolor":"white"    ,"xtick.color":"white"    , "ytick.color":"white"    , "figure.facecolor":"white"  }):  fig = plt.figure(figsize=(30, 24), facecolor="black")  ax = fig.add_subplot(111, facecolor="black")for _, team in team_defense_stats.iterrows():  #read image file  image = plt.imread(root + "image/" + str(team.defteam) + ".png")  ax.add_artist( #ax can be added image as artist.    AnnotationBbox(      OffsetImage(image)      ,(team.yards_gained_passing, team.yards_gained_rushing)      ,frameon=False    )  )ax.set_xlabel("Pass Defense (Yds)", color="white", size=24)ax.set_ylabel("Run Defense (Yds)", color="white", size=24)ax.set_xlim(5000, 2500) #less is betterax.set_ylim(2500, 1000) #less is betterax.tick_params(axis="x", labelsize=24)ax.tick_params(axis="y", labelsize=24)plt.title("Team Defensive Stats", color="white", size=30)

Looks better? It’s easy to understand where team is but I think marker with color bar is better than team logo in terms of data visualization including more information.

看起来好点吗? 很容易理解团队的位置,但是我认为带有颜色条的标记比包含更多信息的数据可视化要好于团队徽标。

Thank you for reading.

感谢您的阅读。

翻译自: https://medium.com/the-sports-scientist/nfl-2020-preview-with-python-team-defense-729bbdfa1b15

nfl定理


http://www.taodudu.cc/news/show-5372731.html

相关文章:

  • 高中英语名人名言(二)
  • 四大组件:Activity生命周期-Android12
  • MEM/MBA 复试准备(05-05)英语面试常见问题36-45
  • keepalived 结合mysql 自动切换
  • In silico saturation mutagenesis of cancer genes 解读
  • nfl定理_NFL 2020预览与python冲
  • biostar handbook(十)|如何进行变异检测
  • Android 锁屏状态下启动应用很慢的原因分析
  • yolov5使用知识蒸馏
  • BiometricPrompt之六 - BiometricDialogView锁屏显示
  • Nothing Ventured, Nothing Gained
  • 声控助手_我从构建声控机器人获得的见解
  • 在线查看word、excel、powerpoint文件
  • Markdown Online PPT
  • 【前端实现在线预览ppt、word、xls、pdf、视频】
  • 阿诺德Arnold渲染器 (R20-2023版本合集)
  • 用MAYA阿诺德(Arnold)渲染器渲染科幻全息线框效果经验笔记
  • 删除maya阿诺德渲染器所有AOVS层
  • marlin 源码入门3
  • marlin 源码入门2
  • marlin 源码入门1
  • Codeforces 980B Marlin(构造)
  • Marlin基础配置(转载收藏)
  • marlin固件烧录教程_marlin2.0应用到STM32实践(续)
  • 关于Marlin的一点认识
  • visual2019没有勾选的在如何加入_批量下载天猫商品时,如何过滤gif格式详情图的实例...
  • 蓝牙定位之蓝牙5.1,升级技术的优点介绍——新导智能
  • 蓝牙定位系统有什么优势
  • 蓝牙定位,多种应用方式的新技术
  • 蓝牙定位5.0技术,高精度定位,你get到了吗?--新导智能

nfl定理_NFL 2020预览与python团队防御相关推荐

  1. nfl定理_NFL 2020预览与python冲

    nfl定理 NFL 2020 season is coming soon. For preview this season, I'm going to visualize some rushing d ...

  2. 金山毒霸技术预览版1.0 beta【云沙箱 三引擎】发布(毒霸体验团队可优先测试)...

    关于金山毒霸技术预览版: 金山毒霸技术预览版是一款基于金山云安全体系,具备智能主动防御和沙箱技术的杀毒软件,无缝连接金山云安全后台服务,将未知程序隔离在沙箱中运行,对真正使用中的系统无任何影响,从而完 ...

  3. 【玩转云函数】腾讯云云函数结合金山文档打造轻量级 Office 在线预览服务

    以下内容来自「玩转腾讯云」用户原创文章,已获得授权. 本文介绍下如何使用云函数来实现 Office 办公文件的预览 01. 前言 曾几何时,文档预览曾经很麻烦,小公司需要购买服务器,自行搭建文件服务器 ...

  4. 看懂nfl定理需要什么知识_NFL球队为什么不经常通过?

    看懂nfl定理需要什么知识 Debunking common NFL myths in an analytical study on the true value of passing the bal ...

  5. idea网页预览功能_IDEA 2020.2 重磅发布,动画级新功能预览!

    博主关注了 IDEA 的官推,平时没事就会去看看有没有啥比较好的更新.今天下午看到IntelliJ IDEA 2020.2 都已经发布并且还支持了 Java15.然后,我就去官网简单看了一下新特性.单 ...

  6. IDEA 2020.2 重磅发布,动画级新功能预览!

    点击上方 好好学java ,选择 星标 公众号 重磅资讯.干货,第一时间送达今日推荐:2020年7月程序员工资统计,平均14357元,又跌了,扎心个人原创100W+访问量博客:点击前往,查看更多 本文 ...

  7. csv 20位数据 如何打开可以预览完整数字_干货Python Pandas 做数据分析之玩转 Excel 报表分析...

    本篇文章选自作者在 GitChat 的分享,若有什么问题,可在公众号回复「小助手」添加小助手微信,邀请你进入技术交流群. 各位朋友大家好,非常荣幸和大家聊一聊用 Python Pandas 处理 Ex ...

  8. python 在线预览文件_用Python PyQt写一个在线预览图片的GUI

    在爬完网上一篇帖子,并得到其中的所有图片链接后,写一个GUI来实现在线预览是一个很自然的想法, 相当于实现一个python版的图片浏览器, 通过这个练习,可以让我们更熟悉PyQt这个库. 这里我用的是 ...

  9. Python excel转成html页面 excel 在线预览

    Python excel转成html页面 excel 在线预览 因为这两天公司的项目要用到在浏览excel 所以就在做这个功能.一开始查了很多资料 都是各种不行,最后好不容易找到一些辅助资料 终于是今 ...

最新文章

  1. InnoDB 引擎独立表空间 innodb_file_per_table
  2. 由铁路订票系统联想到的
  3. J - Milking Time POJ - 3616(dp动态规划)
  4. java继承层次结构,在状态模式中实现继承层次结构 - java
  5. 如何查看有没有django及版本
  6. python-numpy.vectorize()
  7. JS中什么是回调函数?
  8. 【PC工具】压缩包密码破解工具,暴力破解压缩包密码,zip密码获取
  9. 建筑建材行业SaaS多租户用户管理系统:高度整合企业资源,探索数字化转型新路径
  10. linux的gromacs模拟分子运动,动力学模拟gromacs(绝对详细).ppt
  11. C#编程,输入里程数和耗油量,计算每升的里程数,程序中使用异常处理器,当输入的里程数或耗油量无法转换成double值时处理FormatException。
  12. TypeScript 高级类型及用法
  13. 金蝶生成凭证模板_金蝶凭证导入模板
  14. MATLAB操作学习---起式
  15. linux下用vi,vim编辑时退出编辑模式(wq)无法保存退出
  16. pip安装和使用 (Python)
  17. 干货!区块链入门、进阶、行业专家观点!1000篇好文帮你破解区块链密码!(中篇)...
  18. react本地储存_如何在React项目中利用本地存储
  19. linux命令总结-ls
  20. Python读取dll库报错:[WinError 126]找不到指定的模块

热门文章

  1. gflags的使用教程
  2. 1万3千多初中生物题库ACCESS数据库
  3. 2008年毕业生工资大曝光
  4. 让“数字鸿沟”变为“数字通途”
  5. gdb调试当前运行的程序
  6. nodejs环境配置
  7. 技术分享|Flow接入节点(Access node)重构介绍
  8. outlook2013升级_如何仅在Outlook 2013中查看今天的RSS源
  9. 网络安全工程师在面试安全岗位时,哪些内容是加分项?
  10. 记本周的技能get!