Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Python
Analyzing Baseball Data With Python
PyCon JP 2016 Talk Session 2016/9/22
Shinichi Nakagawa, Ai Makabi
Starting Member
• Who am I ?
• Hack→! Hack!!
• (MLBAM) Python & (pitchpx)
• Jupyter lab, pandas, matplotlib
• LT
•
• VS ※
...
Who am I?
• Shinichi Nakagawa(@shinyorke)
• Python ※
• visasQ( ) Web Engineer
• Pythonista, Agile & Scrum & Kanban coach, ...
visasQ?
• .
• 1 2 

.
• Django .
• https://service.visasq.com
• CTO LT (ry
hack?
• ( ) Python OSS .
• ” ” .

Web (
• .

→ !
• (@shinyorke) /MLB
.
Hack! Python
PyCon JP 2015
http://www.slideshare.net/shinyorke/hackpython-pyconjp
Hack! Python
PyCon JP 2015
http://www.slideshare.net/shinyorke/hackpython-pyconjp
Hack! Python
PyCon JP 2015
http://www.slideshare.net/shinyorke/hackpython-pyconjp
Hack!→ Hack!!
• etc…
•
• ( ) 

( , etc…)
• …
•
MLB at BAT MLB
• MLB
• PC TV
• MLB.TV
•
MLBAM Dataset(Pitch f/x)
• MLB Advanced Media(MLB ) XML
.
• PITCH f/x
Statscast Sensor ( / ) .
• ( )100 .
• Copyright , OK...
1
(2016/4/6 VS )
http://gd2.mlb.com/components/game/mlb/year_2016/month_04/day_06/
gid_2016_04_06_lanmlb_sdnmlb_1/inning/i...
MLBAM Dataset( / )
• etc…
•
• ( )
• (Relation)
•
(≒ ).
Analyzing Baseball Data with R
• MLBAM Retrosheet(※ Hack
)
• R(R Studio, pitchRx)
• https://www.amazon.co.jp/dp/B00GBC36S4
PyCon Python
pitchpx - Getting MLB dataset
• MLBAM XML 

CSV .
• pitchRx(R) (@shinyorke) .
• Python 3.3.x ( :Legacy Python!!!).
• Beaut...
$ # Python 3.3 ( Python 3.4 )
$ pip install pitchpx
$ # 2015/8/1-8/12
$ pitchpx -s 20150801 -e 20150812 -o .
Python
• R Python .
• 

(Python)
• Web
API Python .
• Hack
• Jupyter + pandas + matplotlib ,

PyData .
• Jupyter lab .
• INPUT/OUTPUT, pandas.
• matplotlib,seaborn .
• Qiita, .
(Python )
…
LT
• Yu Darvish (@shinyorke)
• 2016 (@amacbee)

※ ( )
• VS (@shinyorke)
Yu Darvish( )
•
•
• (2015) TJ( )
Ichiro Suzuki( )
• & .
• ( ) .
• .
Joey Votto( )
• (2007-2015) .
• .
• 51 PyCon ( ).
Yu Darvish
Yu Darvish(2013, 2016)
• TJ( ) ( etc…)
• TJ (2013) (SL) (FC)
• TJ (2016) 4 (FF) 2 (FT) SL FC
• !?
2013(TJ ) 2016(TJ )
※
'C...
8
• 

http://www.sponichi.co.jp/baseball/news/2016/08/03/kiji/K20160803013085860.html
• ( ) ( )
• ?
5 7 8
• ( DL )
• 5-7 8
• 4
2016/5-7 2016/8
※
'CH': 'Change-up',
'CU': 'Curveball',
'EP': 'Ephuus',
'FA': 'Fastball',
'FC':...
Four seam
• TJ 4 !?
• 2013 (called strike)
• 2016 (swinging strike)
•
2013(TJ ) 2016(TJ )
Ichiro VS Votto
( )
•
51


http://blog.livedoor.jp/
nanjstu/archives/
49340618.html
• 3,000
( )
VS (2016 )
•
• (FF)
• (FT) ( )
• (42) (33) !?
Ichiro Suzuki Joey Votto
※
'CH': 'Change-up',
'CU': 'Curveball',
'EP': 'Ephu...
?
(20 )
??
• ( 165cm) 2
• … (SL).
• ?!?!?!?
• !?( )
Jose Altuve(26) Kris Bryant(24)
※
'CH': 'Change-up',
'CU': 'Curveball',
'EP': 'Ep...
× ×
VS Part2(Hit Zone)
• X (start_speed, ), Y , (pa_event_cd)
• pa_event_cd (20), (21), (22), (23)

※Retrosheet
• pitch_type o...
VS Part2(Hit Zone)
• X (start_speed, ), Y , (pa_event_cd)
• pa_event_cd (20), (21), (22), (23)

※Retrosheet
• pitch_type o...
• 

4 

• ( ) …
•
, 

(& ISSUE )
- -
http://sportsworld.nbcsports.com/bill-james-statistical-revolution/
“””
, .

, 

, 

.
“””
-
• Kawasaki.rb #kwskrb http://kawasakirb.github.io/


PyCon JP 2014 2016,
• BPStudy #bpstudy http://bpstudy.connpass.com/

...
& PyCon JP 2016 !
Shinichi Nakagawa(Twitter/Facebook/visasQ:@shinyorke)
ビックデータとPythonではじめる野球の統計分析 #pyconjp
ビックデータとPythonではじめる野球の統計分析 #pyconjp
ビックデータとPythonではじめる野球の統計分析 #pyconjp
ビックデータとPythonではじめる野球の統計分析 #pyconjp
ビックデータとPythonではじめる野球の統計分析 #pyconjp
Upcoming SlideShare
Loading in …5
×

ビックデータとPythonではじめる野球の統計分析 #pyconjp

6,296 views

Published on

PyCon JP 2016 Talk Session

Pythonと野球データの分析事例について.

Published in: Sports
  • Be the first to comment

ビックデータとPythonではじめる野球の統計分析 #pyconjp

  1. 1. Python Analyzing Baseball Data With Python PyCon JP 2016 Talk Session 2016/9/22 Shinichi Nakagawa, Ai Makabi
  2. 2. Starting Member • Who am I ? • Hack→! Hack!! • (MLBAM) Python & (pitchpx) • Jupyter lab, pandas, matplotlib • LT • • VS ※ • @amacbee •
  3. 3. Who am I? • Shinichi Nakagawa(@shinyorke) • Python ※ • visasQ( ) Web Engineer • Pythonista, Agile & Scrum & Kanban coach, Baseball Analyst • / • • ( ) • 
 8-7 9 .
  4. 4. visasQ? • . • 1 2 
 . • Django . • https://service.visasq.com • CTO LT (ry
  5. 5. hack? • ( ) Python OSS . • ” ” .
 Web ( • .
 → ! • (@shinyorke) /MLB .
  6. 6. Hack! Python PyCon JP 2015 http://www.slideshare.net/shinyorke/hackpython-pyconjp
  7. 7. Hack! Python PyCon JP 2015 http://www.slideshare.net/shinyorke/hackpython-pyconjp
  8. 8. Hack! Python PyCon JP 2015 http://www.slideshare.net/shinyorke/hackpython-pyconjp
  9. 9. Hack!→ Hack!! • etc… • • ( ) 
 ( , etc…) • … •
  10. 10. MLB at BAT MLB • MLB • PC TV • MLB.TV •
  11. 11. MLBAM Dataset(Pitch f/x) • MLB Advanced Media(MLB ) XML . • PITCH f/x Statscast Sensor ( / ) . • ( )100 . • Copyright , OK. • Github . • http://gd2.mlb.com/components
  12. 12. 1 (2016/4/6 VS ) http://gd2.mlb.com/components/game/mlb/year_2016/month_04/day_06/ gid_2016_04_06_lanmlb_sdnmlb_1/inning/inning_1.xml ※ pitcher=“628317"
  13. 13. MLBAM Dataset( / ) • etc… • • ( ) • (Relation) • (≒ ).
  14. 14. Analyzing Baseball Data with R • MLBAM Retrosheet(※ Hack ) • R(R Studio, pitchRx) • https://www.amazon.co.jp/dp/B00GBC36S4
  15. 15. PyCon Python
  16. 16. pitchpx - Getting MLB dataset • MLBAM XML 
 CSV . • pitchRx(R) (@shinyorke) . • Python 3.3.x ( :Legacy Python!!!). • BeautifulSoup( ),click( )
 . • PyPI . • Jupyter, pandas .
  17. 17. $ # Python 3.3 ( Python 3.4 ) $ pip install pitchpx $ # 2015/8/1-8/12 $ pitchpx -s 20150801 -e 20150812 -o .
  18. 18. Python • R Python . • 
 (Python) • Web API Python . • Hack
  19. 19. • Jupyter + pandas + matplotlib ,
 PyData . • Jupyter lab . • INPUT/OUTPUT, pandas. • matplotlib,seaborn . • Qiita, .
  20. 20. (Python ) …
  21. 21. LT • Yu Darvish (@shinyorke) • 2016 (@amacbee)
 ※ ( ) • VS (@shinyorke)
  22. 22. Yu Darvish( ) • • • (2015) TJ( )
  23. 23. Ichiro Suzuki( ) • & . • ( ) . • .
  24. 24. Joey Votto( ) • (2007-2015) . • . • 51 PyCon ( ).
  25. 25. Yu Darvish
  26. 26. Yu Darvish(2013, 2016) • TJ( ) ( etc…) • TJ (2013) (SL) (FC) • TJ (2016) 4 (FF) 2 (FT) SL FC • !? 2013(TJ ) 2016(TJ ) ※ 'CH': 'Change-up', 'CU': 'Curveball', 'EP': 'Ephuus', 'FA': 'Fastball', 'FC': 'Cut Fastball', 'FF': 'four-seam Fastball', 'FO': 'Forkball', 'FS': 'Split-finger Fastball', 'FT': 'two-seam Fastball', 'KC': 'Knuckle Curve', 'KN': 'Knuckleball', 'SC': 'Screwball', 'SI': 'Sinker', 'SL': 'Slider', 'UN': 'Unknown'
  27. 27. 8 • 
 http://www.sponichi.co.jp/baseball/news/2016/08/03/kiji/K20160803013085860.html • ( ) ( ) • ?
  28. 28. 5 7 8 • ( DL ) • 5-7 8 • 4 2016/5-7 2016/8 ※ 'CH': 'Change-up', 'CU': 'Curveball', 'EP': 'Ephuus', 'FA': 'Fastball', 'FC': 'Cut Fastball', 'FF': 'four-seam Fastball', 'FO': 'Forkball', 'FS': 'Split-finger Fastball', 'FT': 'two-seam Fastball', 'KC': 'Knuckle Curve', 'KN': 'Knuckleball', 'SC': 'Screwball', 'SI': 'Sinker', 'SL': 'Slider', 'UN': 'Unknown'
  29. 29. Four seam • TJ 4 !? • 2013 (called strike) • 2016 (swinging strike) • 2013(TJ ) 2016(TJ )
  30. 30. Ichiro VS Votto
  31. 31. ( ) • 51 
 http://blog.livedoor.jp/ nanjstu/archives/ 49340618.html • 3,000
  32. 32. ( )
  33. 33. VS (2016 ) • • (FF) • (FT) ( ) • (42) (33) !? Ichiro Suzuki Joey Votto ※ 'CH': 'Change-up', 'CU': 'Curveball', 'EP': 'Ephuus', 'FA': 'Fastball', 'FC': 'Cut Fastball', 'FF': 'four-seam Fastball', 'FO': 'Forkball', 'FS': 'Split-finger Fastball', 'FT': 'two-seam Fastball', 'KC': 'Knuckle Curve', 'KN': 'Knuckleball', 'SC': 'Screwball', 'SI': 'Sinker', 'SL': 'Slider', 'UN': 'Unknown'
  34. 34. ? (20 ) ??
  35. 35. • ( 165cm) 2 • … (SL). • ?!?!?!? • !?( ) Jose Altuve(26) Kris Bryant(24) ※ 'CH': 'Change-up', 'CU': 'Curveball', 'EP': 'Ephuus', 'FA': 'Fastball', 'FC': 'Cut Fastball', 'FF': 'four-seam Fastball', 'FO': 'Forkball', 'FS': 'Split-finger Fastball', 'FT': 'two-seam Fastball', 'KC': 'Knuckle Curve', 'KN': 'Knuckleball', 'SC': 'Screwball', 'SI': 'Sinker', 'SL': 'Slider', 'UN': 'Unknown'
  36. 36. × ×
  37. 37. VS Part2(Hit Zone) • X (start_speed, ), Y , (pa_event_cd) • pa_event_cd (20), (21), (22), (23)
 ※Retrosheet • pitch_type orz ※ 'CH': 'Change-up', 'CU': 'Curveball', 'EP': 'Ephuus', 'FA': 'Fastball', 'FC': 'Cut Fastball', 'FF': 'four-seam Fastball', 'FO': 'Forkball', 'FS': 'Split-finger Fastball', 'FT': 'two-seam Fastball', 'KC': 'Knuckle Curve', 'KN': 'Knuckleball', 'SC': 'Screwball', 'SI': 'Sinker', 'SL': 'Slider', 'UN': 'Unknown' Ichiro Suzuki Joey Votto
  38. 38. VS Part2(Hit Zone) • X (start_speed, ), Y , (pa_event_cd) • pa_event_cd (20), (21), (22), (23)
 ※Retrosheet • pitch_type orz ※ 'CH': 'Change-up', 'CU': 'Curveball', 'EP': 'Ephuus', 'FA': 'Fastball', 'FC': 'Cut Fastball', 'FF': 'four-seam Fastball', 'FO': 'Forkball', 'FS': 'Split-finger Fastball', 'FT': 'two-seam Fastball', 'KC': 'Knuckle Curve', 'KN': 'Knuckleball', 'SC': 'Screwball', 'SI': 'Sinker', 'SL': 'Slider', 'UN': 'Unknown' Ichiro Suzuki Joey Votto
  39. 39. • 
 4 
 • ( ) … • , 
 (& ISSUE )
  40. 40. - - http://sportsworld.nbcsports.com/bill-james-statistical-revolution/
  41. 41. “”” , .
 , 
 , 
 . “”” -
  42. 42. • Kawasaki.rb #kwskrb http://kawasakirb.github.io/ 
 PyCon JP 2014 2016, • BPStudy #bpstudy http://bpstudy.connpass.com/
 BPStudy Hack . •
  43. 43. & PyCon JP 2016 ! Shinichi Nakagawa(Twitter/Facebook/visasQ:@shinyorke)

×