{"id":1828,"date":"2020-08-28T01:04:51","date_gmt":"2020-08-28T01:04:51","guid":{"rendered":"http:\/\/optimumsportsperformance.com\/blog\/?p=1828"},"modified":"2022-11-08T03:39:50","modified_gmt":"2022-11-08T03:39:50","slug":"python-tips-tricks-coding-a-tensorflow-neural-network-to-predict-yards-after-catch","status":"publish","type":"post","link":"https:\/\/optimumsportsperformance.com\/blog\/python-tips-tricks-coding-a-tensorflow-neural-network-to-predict-yards-after-catch\/","title":{"rendered":"Python Tips &#038; Tricks: Coding A Tensorflow Neural Network to Predict Yards After Catch"},"content":{"rendered":"<p>As I work to improve my python skills, I&#8217;ll keep adding my efforts to the blog. This week, I saw a nice article showing a basic approach to coding a <strong><span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/www.opensourcefootball.com\/posts\/2020-08-19-neural-nets-using-r\/\">neural network in R to predict yards after catch in NFL receivers<\/a><\/span><\/strong> from the folks at <strong><span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/www.opensourcefootball.com\/\">www.opensourcefootball.com<\/a><\/span><\/strong>. So, I decided to take that idea and try and create my own neural network in Python.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Some notes:<\/strong><\/span><\/p>\n<ol>\n<li>This is not a to say that the neural network was the best method to answer the question. Rather, it was just a way for me to try and take stuff I&#8217;d already do in R and see if I could learn it in Python.<\/li>\n<li>This is not a blog post to cover all aspects of neural networks (not even close). It just so happened that the original article used a neural network via <span style=\"color: #0000ff;\"><strong>tensorflow<\/strong><\/span> in R and I happened to be doing some work in <span style=\"color: #0000ff;\"><strong>tensorflow<\/strong><\/span> in Python this week, so it was an easy connection to make.<\/li>\n<li>My Python coding is pretty messey and at times I feel like it takes me several steps to do what someone might do in a few lines. Feel free to comment and offer suggestions.<\/li>\n<li>Harking back to point one, I finish the script by coding a linear regression model to answer the same question (predict yards after catch) as it is a simpler and more interpretable than a neural network. I construct the regression model in two ways. First, I do it in <span style=\"color: #0000ff;\"><strong>sklearn<\/strong><\/span>, which seems to be the preferred approach to coding models by pythoners. I then do it in the <strong><span style=\"color: #0000ff;\">statsmodels<\/span><\/strong> library. I&#8217;m sure this is more a function of my poor python programming skills but I do feel like the model output from <span style=\"color: #0000ff;\"><strong>statsmodels<\/strong> <\/span>is more informative than what I can get returned from <span style=\"color: #0000ff;\"><strong>sklearn<\/strong><\/span> (and I show this in the script).<\/li>\n<\/ol>\n<p>The data came from <strong><span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/github.com\/guga31bb\/nflfastR-data\">nflfastR<\/a><\/span><\/strong>, which is an R package for obtaining NFL play-by-play data created by <strong><span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/twitter.com\/benbbaldwin\">Ben Baldwin<\/a> <\/span><\/strong>et al.<\/p>\n<p>I provide a step-by-step explanation for coding the model on my <strong><span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/github.com\/pw2\/Python-Tips-and-Tricks\/blob\/master\/Tensorflow%20Neural%20Network%20for%20Yards%20After%20Catch.ipynb\">GITHUB page<\/a><\/span><\/strong>.<\/p>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2020\/08\/Screen-Shot-2020-08-27-at-6.04.06-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-1829\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2020\/08\/Screen-Shot-2020-08-27-at-6.04.06-PM-1024x783.png\" alt=\"\" width=\"625\" height=\"478\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2020\/08\/Screen-Shot-2020-08-27-at-6.04.06-PM-1024x783.png 1024w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2020\/08\/Screen-Shot-2020-08-27-at-6.04.06-PM-300x229.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2020\/08\/Screen-Shot-2020-08-27-at-6.04.06-PM-768x587.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2020\/08\/Screen-Shot-2020-08-27-at-6.04.06-PM-624x477.png 624w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2020\/08\/Screen-Shot-2020-08-27-at-6.04.06-PM.png 1221w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I work to improve my python skills, I&#8217;ll keep adding my efforts to the blog. This week, I saw a nice article showing a basic approach to coding a neural network in R to predict yards after catch in NFL receivers from the folks at www.opensourcefootball.com. So, I decided to take that idea and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,46],"tags":[],"class_list":["post-1828","post","type-post","status-publish","format-standard","hentry","category-model-building-in-python","category-python-tips-tricks"],"_links":{"self":[{"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/posts\/1828","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/comments?post=1828"}],"version-history":[{"count":2,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/posts\/1828\/revisions"}],"predecessor-version":[{"id":1831,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/posts\/1828\/revisions\/1831"}],"wp:attachment":[{"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/media?parent=1828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/categories?post=1828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/tags?post=1828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}