52
Py “Baseball” Data PyCon mini Hirosima 2016 Python Shinichi Nakagawa(Baseball Analyst&Pythonista)

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

  • Upload
    -

  • View
    5.060

  • Download
    2

Embed Size (px)

Citation preview

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

Py “Baseball” Data PyCon mini Hirosima 2016

Python

Shinichi Nakagawa(Baseball Analyst&Pythonista)

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

Starting Member

• Who am I?( )

• PyData

• PyData / #

• Python

• PyData + (FIP/RC27)

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

Who am I?

• Shinichi Nakagawa(@shinyorke)

• Python , Hack ※ Python

• HR .

• Python/Agile/PyData/SABRmetrics( )

• ( ) .

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

• ( ) HR .

• 1 2

.

• (Django) Python .

• https://service.visasq.com

• https://tech.visasq.com

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

• &

• etc…

• Web Python

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

• IPython + pandas

(Hello World )

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

.

.

• Deep Learning ,

.

• (Pandas )

& .

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

PyData / #

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

PyData

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

“”” PyData

Python Python Library

“””

※@iktakahiro http://www.slideshare.net/iktakahiro/pydata-67913897

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

PyData

• , ,Python

&( ) .

• , or .

• Excel Python, Deep Learning,

etc… PyData

PyData ( )

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

( )

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

( )

• ,

• 1970

, &

( , )

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

• ( , ,FA)

• ( )

• ( , etc…)

• ( , J )

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

× ( ) ※ × +

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

× ( ) ※ × +

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

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

5

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

• ( - ) = 5 ( )

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

.

• ( - ) 5 5

(ry .

• = ( 2 )÷( 2 + 2 )

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

Python×Pandas

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

Python×pandas

# Python 3 (3.4 ) ( )$ pip install ipython pandas beautifulsoup4 numpy lxml html5lib# ipython ( Jupyter )$ ipython

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

Python×pandas

# import pandas as pdimport numpy as np

# ( )df = pd.read_html('http://baseball.yahoo.co.jp/npb/standings/')

# df_cl = df[0].drop([0]) #

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

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) #

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

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)

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

https://gist.github.com/Shinichi-Nakagawa/8ff55af83390fcd2e2dd34bcb914868c

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

( )

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

×

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

• (+187)

• 5

• /

• DeNA ,

• ( )

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

?

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

( )

• & (& )

• , , ,

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

×PyData

• FIP

• (RC27)

• scrapy CSV

• CSV pandas, seaborn, jupyter &

( )

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

FIP(Fielding Independent Pitching)

• , ( )

• , (+ ),

• ( )

• xFIP

FIP .

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

FIP( TOP 20)

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

FIP( & )

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

FIP(50 Histogram)

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

FIP(50 Histogram)

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

FIP(50 Histogram)

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

FIP

• FIP

FIP ( )

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

RC27

• 9 1

?

• VS , ?

• RC(Run Created, ) 1

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

RC27 (350 )

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

RC27 TOP30(350 )

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

RC27(Histogram)

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

RC27(Histogram)

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

RC27(Histogram)

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

RC27

• 1-6

• RC27 Top30 6

• ( )

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

6 Top30

• ,

• ,

, FIP ( )

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

[ ]

• ,

FIP, WHIP, K/BB, etc…

• ,

RC27 3 ( 6 )

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

Py "Baseball" Data - Python ※pandas, Re:dash (& )

MonotaRO TechTalk #4

http://www.kokuchpro.com/event/monotarotech4/

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

&

Shinichi Nakagawa(Twitter/Facebook/visasQ:@shinyorke)