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.
Py “Baseball” Data
PyCon mini Hirosima 2016
Python
Shinichi Nakagawa(Baseball Analyst&Pythonista)
Starting Member
• Who am I?( )
• PyData
• PyData / #
• Python
• PyData + (FIP/RC27)
•
Who am I?
• Shinichi Nakagawa(@shinyorke)
• Python , Hack ※ Python
• HR .
• Python/Agile/PyData/SABRmetrics( )
•
• ( ) .
• ( ) HR .
• 1 2
.
• (Django) Python .
• https://service.visasq.com
• https://tech.visasq.com
•
•
•
• &
• etc…
• Web Python
•
• IPython + pandas 

(Hello World )
•
• 

.

.
• Deep Learning , 

.
• (Pandas )

& .
PyData / #
PyData
“””
PyData
Python Python Library
“””
※@iktakahiro
http://www.slideshare.net/
iktakahiro/pydata-67913897
PyData
• , ,Python 

&( ) .
• , or .
• Excel Python, Deep Learning,
etc… PyData 

PyData ( )
( )
“””
“””
https://ja.wikipedia.org/
wiki/
( )
• , 

• 1970 

, &
• 

( , )
•
• ( , ,FA)
• ( )
•
• ( , etc…)
• ( , J )
× ( )
※ × +
× ( )
※ × +
※
5
• ( - ) = 5 ( )
•
•
•
•
•
.
• ( - ) 5 5
(ry .
• = ( 2 )÷( 2 + 2 )
•
Python×Pandas
Python×pandas
# Python 3 (3.4 ) ( )
$ pip install ipython pandas beautifulsoup4 numpy lxml html5lib
# ipython ( Jupyter )
...
Python×pandas
#
import pandas as pd
import numpy as np
# ( )
df = pd.read_html('http://baseball.yahoo.co.jp/npb/standings/...
Python×pandas
#
# ( )
df_cl.columns = ['rank', 'name', 'games', 'win', 'lose', 'draw',
'pct', 'gb', 're_games', 'r', 'er',...
Python×pandas
#
df_cl['difference'] = df_cl['r'] - df_cl['er']
#
df_cl['pythagorean_win_per'] = (df_cl['r'] ** 2) / (df_cl...
https://gist.github.com/Shinichi-Nakagawa/8ff55af83390fcd2e2dd34bcb914868c
( )














×
•
• (+187)
• 5
• /
• DeNA ,
•
• ( )
?
( )
• & (& ) 

• , , ,
•
×PyData
• FIP
• (RC27)
• scrapy CSV
• CSV pandas, seaborn, jupyter & 



( )
FIP(Fielding Independent Pitching)
• , ( )
• , (+ ),
• ( )
• xFIP 

FIP .
FIP( TOP 20)
FIP( & )
FIP(50 Histogram)
FIP(50 Histogram)
FIP(50 Histogram)
FIP
•
•
•
• FIP
• 

FIP ( )
RC27
• 9 1
?
• VS , ?
• RC(Run Created, ) 1
•
RC27 (350 )
RC27 TOP30(350 )
RC27(Histogram)
RC27(Histogram)
RC27(Histogram)
RC27
• 1-6
• RC27 Top30 6
•
•
•
• ( )
• 

6 Top30 

• ,
• ,
, FIP ( )
•
[ ]
• , 

FIP, WHIP, K/BB, etc…
• , 

RC27 3 ( 6 )
•
Py "Baseball" Data - Python
※pandas, Re:dash (& )
MonotaRO TechTalk #4
http://www.kokuchpro.com/event/monotarotech4/
&
Shinichi Nakagawa(Twitter/Facebook/visasQ:@shinyorke)
Py "Baseball" Data入門 - 広島東洋カープ編 #pyconhiro
Upcoming SlideShare
Loading in …5
×

Py "Baseball" Data入門 - 広島東洋カープ編 #pyconhiro

12,753 views

Published on

Pythonと野球統計学「セイバーメトリクス」を用いて,2016年セ・リーグ優勝の広島東洋カープの強さの秘密は何だったのか?に迫ります.

PyCon mini Hiroshima 2016発表資料 http://hiroshima.pycon.jp/

Published in: Data & Analytics
  • Be the first to comment

Py "Baseball" Data入門 - 広島東洋カープ編 #pyconhiro

  1. 1. Py “Baseball” Data PyCon mini Hirosima 2016 Python Shinichi Nakagawa(Baseball Analyst&Pythonista)
  2. 2. Starting Member • Who am I?( ) • PyData • PyData / # • Python • PyData + (FIP/RC27) •
  3. 3. Who am I? • Shinichi Nakagawa(@shinyorke) • Python , Hack ※ Python • HR . • Python/Agile/PyData/SABRmetrics( ) • • ( ) .
  4. 4. • ( ) HR . • 1 2 . • (Django) Python . • https://service.visasq.com • https://tech.visasq.com
  5. 5. • • • • & • etc… • Web Python
  6. 6. • • IPython + pandas 
 (Hello World ) •
  7. 7. • 
 .
 . • Deep Learning , 
 . • (Pandas )
 & .
  8. 8. PyData / #
  9. 9. PyData
  10. 10. “”” PyData Python Python Library “”” ※@iktakahiro http://www.slideshare.net/ iktakahiro/pydata-67913897
  11. 11. PyData • , ,Python 
 &( ) . • , or . • Excel Python, Deep Learning, etc… PyData 
 PyData ( )
  12. 12. ( )
  13. 13. “”” “”” https://ja.wikipedia.org/ wiki/
  14. 14. ( ) • , 
 • 1970 
 , & • 
 ( , )
  15. 15. • • ( , ,FA) • ( ) • • ( , etc…) • ( , J )
  16. 16. × ( ) ※ × +
  17. 17. × ( ) ※ × +
  18. 18.
  19. 19. 5
  20. 20. • ( - ) = 5 ( ) • • • •
  21. 21. • . • ( - ) 5 5 (ry . • = ( 2 )÷( 2 + 2 ) •
  22. 22. Python×Pandas
  23. 23. Python×pandas # Python 3 (3.4 ) ( ) $ pip install ipython pandas beautifulsoup4 numpy lxml html5lib # ipython ( Jupyter ) $ ipython
  24. 24. Python×pandas # import pandas as pd import numpy as np # ( ) df = pd.read_html('http://baseball.yahoo.co.jp/npb/standings/') # df_cl = df[0].drop([0]) #
  25. 25. Python×pandas # # ( ) df_cl.columns = ['rank', 'name', 'games', 'win', 'lose', 'draw', 'pct', 'gb', 're_games', 'r', 'er', 'hr', 'sb', 'ba', 'era'] # df_cl['win'] = df_cl['win'].fillna(0).astype(np.int64) # df_cl['lose'] = df_cl['lose'].fillna(0).astype(np.int64) # df_cl['pct'] = df_cl['pct'].fillna(0).astype(np.float64) # df_cl['r'] = df_cl['r'].fillna(0).astype(np.int64) # df_cl['er'] = df_cl['er'].fillna(0).astype(np.int64) #
  26. 26. Python×pandas # df_cl['difference'] = df_cl['r'] - df_cl['er'] # df_cl['pythagorean_win_per'] = (df_cl['r'] ** 2) / (df_cl['r'] ** 2 + df_cl['er'] ** 2) # df_cl['pythagorean_win'] = (df_cl['pythagorean_win_per'] * 143).fillna(0).astype(np.int64) df_cl['pythagorean_lose'] = 143 - df_cl['pythagorean_win'] # df_cl.sort_values(by='pythagorean_win_per', ascending=False)
  27. 27. https://gist.github.com/Shinichi-Nakagawa/8ff55af83390fcd2e2dd34bcb914868c
  28. 28. ( ) 
 
 
 
 
 
 

  29. 29. ×
  30. 30. • • (+187) • 5 • / • DeNA , • • ( )
  31. 31. ?
  32. 32. ( ) • & (& ) 
 • , , , •
  33. 33. ×PyData • FIP • (RC27) • scrapy CSV • CSV pandas, seaborn, jupyter & 
 
 ( )
  34. 34. FIP(Fielding Independent Pitching) • , ( ) • , (+ ), • ( ) • xFIP 
 FIP .
  35. 35. FIP( TOP 20)
  36. 36. FIP( & )
  37. 37. FIP(50 Histogram)
  38. 38. FIP(50 Histogram)
  39. 39. FIP(50 Histogram)
  40. 40. FIP • • • • FIP • 
 FIP ( )
  41. 41. RC27 • 9 1 ? • VS , ? • RC(Run Created, ) 1 •
  42. 42. RC27 (350 )
  43. 43. RC27 TOP30(350 )
  44. 44. RC27(Histogram)
  45. 45. RC27(Histogram)
  46. 46. RC27(Histogram)
  47. 47. RC27 • 1-6 • RC27 Top30 6 • • • • ( )
  48. 48. • 
 6 Top30 
 • , • , , FIP ( ) •
  49. 49. [ ] • , 
 FIP, WHIP, K/BB, etc… • , 
 RC27 3 ( 6 ) •
  50. 50. Py "Baseball" Data - Python ※pandas, Re:dash (& ) MonotaRO TechTalk #4 http://www.kokuchpro.com/event/monotarotech4/
  51. 51. & Shinichi Nakagawa(Twitter/Facebook/visasQ:@shinyorke)

×