Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ScrapyとRedashではじめる野球統計学 #PyConKuma

ScrapyとRedashではじめる野球統計学 #PyConKuma

福岡ソフトバンクホークスと北海道日本ハムファイターズの分析をScrapy,Redashでやりました.

PyCon mini Kumamoto 2017発表資料 http://kumamoto.pycon.jp/

#Python #Baseball

2c0947c6a28e7f771ebd9859ecf54e5c?s=128

Shinichi Nakagawa

April 23, 2017
Tweet

Transcript

  1. ScrapyͱRedashͰ͸͡ΊΔ໺ٿ౷ܭֶ ʙ෱ԬιϑτόϯΫϗʔΫεΛఴ͑ͯʙ Shinichi Nakagawa(Retty.Inc Engineer/Baseball Analyst) PyCon mini Kumamoto 2017

    Talk Session
  2. ϢχϑΥʔϜΛਖ਼૷Խ͠Α͏ʂ ※ࣸਅ෇͖ͰγΣΞ͓ئ͍͠·͢ʂ

  3. Who am I ?(͓લ୭Α) • Shinichi Nakagawa • @shinyorke /

    ໺ٿͷਓ • Retty.Inc Engineer/ڕྉཧ୲౰ • Python/໺ٿ/ηΠόʔϝτϦΫε/Agile • PythonͰ໺ٿσʔλ෼ੳ&AgileͳϒϩάΛॻ͍ͯΔਓ
  4. ϒϩάʮLean Baseballʯ • http://shinyorke.hatenablog.com/ • ໺ٿɾPythonɾAgileத৺ͷϒϩάͰ͢ • ʮPython ຊʯʮ໺ٿ౷ܭֶʯʮηΠόʔϝτϦΫεʯͰΑ͘ݕࡧ͞Ε·͢(ײँ) •

    ॳ৺ऀ͕PythonΛ֮͑ΔҝͷຊͷબͼํΛମܥԽͯ͠Έͨ(2017൛) • ໺ٿ޷͖͕౷ܭֶΛ֮͑ΔҝͷֶशϑϩʔΛ࡞ͬͯΈ·ͨ͠ • ʲ໺ٿʳ30෼ͰΘ͔ΔηΠόʔϝτϦΫε • ࠓ೔ͷൃදͷิ଍ɾղઆ͸͍ͣΕϒϩάʹॻ͘༧ఆͰ͢
  5. Starting member(͓͠ͳ͕͖) • ScrapyͱRedashͰ࡞Δ໺ٿ෼ੳج൫ • ScrapyͰσʔλΛूΊΔ • ηΠόʔϝτϦΫεࢦඪΛࢉग़͢ΔύοέʔδΛ࡞ͬͨ&࢖ͬͨ • RedashͰՄࢹԽ͢Δ

    • ෱ԬιϑτόϯΫϗʔΫεVS๺ւಓ೔ຊϋϜϑΝΠλʔζʙηΠόʔϝτϦΫεΛఴ͑ͯ • ಘ఺૑ग़ೳྗ(RC/RC27) • ಘ఺Ձ஋(wOBA/wRAA) • ·ͱΊ
  6. ScrapyͱRedashͰ࡞Δ ໺ٿ෼ੳج൫

  7. ࠓճ࡞ͬͨ͘͠Έ

  8. ࠓճ࡞ͬͨ͘͠Έ ɾσʔλΛ͋ͭΊΔ ɾܭࢉ͢Δ ɾMySQLʹอଘ͢Δ ɾσʔλΛநग़͢Δ ɾՄࢹԽ͢Δ ɾϨϙʔτΛ࡞Δ

  9. ࠓճ࡞ͬͨ͘͠Έ ɾσʔλΛ͋ͭΊΔ ɾܭࢉ͢Δ ɾMySQLʹอଘ͢Δ ɾσʔλΛநग़͢Δ ɾՄࢹԽ͢Δ ɾϨϙʔτΛ࡞Δ venv(Python3) Docker VirtualBox

    ϗετ04˞ࠓճ͸.BD04
  10. Scrapy #ͱ͸

  11. ScrapyʙΫϩʔϥʔFW • WebαΠτͷΫϩʔϧͱεΫϨΠϐϯά,σʔλͷอଘͳ ͲΛҰؾ௨؏ʹߦ͑ΔΫϩʔϥʔFW • ΫϩʔϥʔքͷDjango/Ruby On RailsͱݺΜͰ͍͍ଘࡏ • εέδϡʔϥʔ,UserAgent,HTTP

    Header,μ΢ϯϩʔυͷ λΠϛϯά,Ωϟογϡetc…ඞཁʹͳΔ΋ͷ͕͋Β͔͡Ί ༻ҙ͞Ε͍ͯΔ&ύϥϝʔλͷઃఆͳͲͰ؆୯ʹઃఆՄೳ
  12. Scrapyͷશମ૾ https://doc.scrapy.org/en/1.0/topics/architecture.html

  13. Scrapyͷશମ૾ https://doc.scrapy.org/en/1.0/topics/architecture.html ίϯϙʔωϯτؒΛ੍ޚ ɾεΫϨΠϐϯά ɾ݁ՌΛItemʹอଘ ΩϡʔʹஷΊΔ&࣮ߦ αΠτΛμ΢ϯϩʔυ ɾItemΛValidate ɾσʔλͱͯ͠อଘ ScrapyͷػೳΛ׆༻

    ։ൃऀ͕ઃܭɾ࣮૷
  14. ScrapyͰͷ։ൃͷجຊ • Spider/ItemΛ࡞Δ • SpiderɿΫϩʔϥʔ&εΫϨΠϐϯάͷఆٛ,MVCͷVͱC. • ItemɿεΫϨΠϐϯάͷ݁ՌΛอଘ,MVCͷMͳ෦෼. • Item PipelineΛ࡞Δ

    • Itemͷ಺༰ΛValidate͢Δ ※ࠓճ͸ະ࣮ࢪ • ItemΛอଘ͢Δ(CSV,XML,JSON,Database,etc…)
  15. ࣮ྫʙ໺ٿͷ৔߹ ※งғؾͷΈͰ͢ #࡯͠

  16. Spider(ଧऀσʔλΛऔΔ&อଘ) from scrapy import Spider, Request from ..items import BaseballNpbPlayer

    as Player class BatterStatsSpider(Spider): name = 'player_stats' allowed_domains = ['example.com'] start_urls = _get_start_urls() BASE_URL = ‘http://example.com' def parse(self, response): for row in response.xpath('//table[@class="NpbPlSt mb10"]/tr'): if len(row.xpath('td[2]').extract()) > 0: name = row.xpath('td[2]/a/text()').extract()[0] url = ''.join([self.BASE_URL, row.xpath('td[2]/a/@href').extract()[0]]) yield Request(url, callback=self.parse_player) def parse_player(self, response): """ ίʔϧόοΫؔ਺ """ stats = Player() # লུ yield stats
  17. Item(ଧऀσʔλΛอଘ) import scrapy class BaseballNpbPlayer(scrapy.Item): # profile name = scrapy.Field()

    # ໊લ url = scrapy.Field() # URL born = scrapy.Field() # ੜ೥݄೔ throw_bat = scrapy.Field() # ར͖࿹/ଧ੮ team = scrapy.Field() # νʔϜ # batting ba = scrapy.Field() # ଧ཰ hr = scrapy.Field() # ϗʔϜϥϯ rbi = scrapy.Field() # ଧ఺ # লུ obp = scrapy.Field() # ग़ྥ཰ slg = scrapy.Field() # ௕ଧ཰ ops = scrapy.Field() # OPS
  18. Item Pipeline(SQLAlchemyͷྫ) from configparser import ConfigParser import logging from sqlalchemy

    import create_engine from sqlalchemy.orm import sessionmaker from .models import PlayerBatting, PlayerPitching # SQLAlchemyͷϞσϧΫϥεͱࢥ͍ͬͯͩ͘͞ class BaseballLabPipeline(object): URL = '{dialect}+{driver}://{user}:{password}@{host}:{port}/{database}?charset={encoding}' def open_spider(self, spider): """ Spider͔Βݺ͹Εͨ࣌ͷॳظॲཧ """ config = ConfigParser() config.read('./config.ini') params = dict(config['mysql']) engine = create_engine(cls.URL.format(**params), encoding=params.get('encoding')) Session = sessionmaker() Session.configure(bind=engine) self.session = Session() def close_spider(self, spider): """ ऴྃॲཧ """ try: logging.info('close spider') finally: self.session.close()
  19. Item Pipeline(SQLAlchemyͷྫ) @classmethod def create_model(cls, item, spider): """ ଧऀ/౤खσʔλͷΠϯελϯεΛฦ͢ """

    if spider.name == 'player_batting': return PlayerBatting(**item) elif spider.name == 'player_pitching': return PlayerPitching(**item) else: raise Exception('Spider not found{}'.format(spider.name)) def process_item(self, item, spider): """ ItemΛDBʹอଘ """ try: self.session.add(BaseballLabPipeline.create_model(item, spider)) self.session.commit() except Exception as e: self.session.rollback() logging.error(e) logging.error(item)
  20. ScrapyͰ΍ͬͨ͜ͱ • Spider • ໺ٿબखϖʔδ(࡯͠)ͷϦετΛparse()Ͱऔಘ • callbackؔ਺಺ʹબख(ݸਓ)ͷεΫϨΠϐϯά࣮૷ • Item •

    ଧऀɾ౤खɾνʔϜຖʹItemΫϥεΛ࡞੒ • ϝϯόʔ͸໺ٿࢦඪ஋ͷུশ(୹ͯ͘ಡΈ΍͍͢) • Item Pipeline • SQLAlchemy(O/R mapping)ΛऔΓࠐΜͰָʹॻ͚ΔΑ͏ʹ • ॲཧର৅ͷSpiderʹ߹ΘͤͯอଘઌϞσϧ(SQLAlchemy)Λมߋ
  21. ιʔείʔυ͸ެ։… ͠·ͤΜ #࡯͠

  22. ScrapyҎ֎Ͱ޻෉ͨ͠ͱ͜Ζ • ʲProblemʳSpider಺ͷࢦඪ஋ܭࢉ͕൥ࡶԽ • RC/RC27(ಘ఺૑ग़ೳྗ) • wOBA(ॏΈ෇͖ग़ྥ཰) • wRAA(ଧऀͷଧܸߩݙ౓) •

    Spiderʹ௚઀ॻ͘಺༰͡Όͳ͍&ଞͷ෼ੳͰ΋࢖͍·Θ͍ͨ͠ʂ • ʲTryʳηΠόʔϝτϦΫεࢦඪΛPythonͷύοέʔδͱͯ͠੾Γग़ͨ͠
  23. SABR(໺ٿ౷ܭֶϥΠϒϥϦ) • GithubΛάάͬͯ΋ແ͔ͬͨͷͰࣗ࡞ͯ͠PyPIʹެ։ • OPS,RC,wOBA,wRAA,ΞμϜɾμϯ཰ͳͲΛܭࢉ͢Δ ΫϥεΛύοέʔδԽͨ͠ • https://github.com/Shinichi-Nakagawa/sabr • SABR͸΋ͪΖΜʮSABRmetricsʯͷ͜ͱ


    ୭΋࢖ͬͯͳ͔ͬͨͷͰಊʑͱొ࿥͠·ͨ͠w
  24. SABR(Example) $ pip install sabr $ python >>> import sabr

    >>> from sabr.stats import Stats >>> Stats.hr9(26, 209.7) # Yu Darvish(2013) HR/9 1.1
  25. Redash #ͱ͸

  26. Redash • WebαʔϏεͰ࢖͏σʔλΛάϥϑͰՄࢹԽ͢ΔͨΊͷπʔϧ • RDBMS, KVS, Google Analytics,etc…༷ʑͳσʔλιʔεʹରԠ • Ϋϥ΢υαʔϏε༗Γ(༗ྉ)ɺιʔεͦͷ΋ͷ͕OSS


    AWS(EC2)/GCE/DockerͰΠϝʔδ΋ެ։͞Ε͍ͯΔ • ϝΠϯͷΞϓϦέʔγϣϯ͸Flask(Python) + Angular JS
 Mail΍SlackͳͲ΁ͷ௨஌ʹ΋ରԠ • ݸਓͰSQLΛ͍ͬͨ͡ΓάϥϑΛͪΐ͍ͪΐ͍ඳ͘໨తͰ࢖͍΍͍͢
  27. ϩʔΧϧ؀ڥ(Mac OS)Ͱͷ࡞Γํ VISASQ TECH BLOGʮRe:dashͱDocker for MacͰΒ͘Β͘෼ੳɾՄࢹԽ؀ڥߏஙʯ ※@shinyorke͕લ৬࣌୅ʹ࣮ફͨ͠ϞϊͰ͢ https://tech.visasq.com/redash-docker/

  28. ෼ੳ(Query) ࠓճ͸MySQL,ͻͨ͢ΒQueryΛॻ͖ଓ͚Δ

  29. ՄࢹԽ(άϥϑΛඳ͘) σʔληοτΛݩʹઃఆΛ஍ಓʹߦͬͯඳ͘

  30. Scrapy(&sabr)ͱRedash·ͱΊ • ScrapyͰఆظతʹ໺ٿσʔλΛऔΔ࢓૊Έ͕Ͱ͖ͨ • ໘౗͍͘͞ࢦඪ஋ܭࢉΛsabrͱ͍͏ύοέʔδʹ
 ࠓޙ,WebΞϓϦ΍ଞͷ෼ੳͰ΋࢖͍·ΘͤΔʂ • RedashͰSQLΛͪΐΖͬͱॻ͘ʮ͚ͩʯͰՄࢹԽͱ͔ ෼ੳ͕ࡁΜ͡Ό͏؀ڥ •

    ෼ੳج൫ͦͷ΋ͷ͸΄΅࣮૷θϩʂͰͨ͠.
  31. ͔͜͜Βઌ͸͓଴͔ͪͶ…ͷ

  32. None
  33. 2016೥ύɾϦʔά;Γ͔͑Γ
 ʙ೔ϋϜVSϗʔΫεʙ

  34. ࠓճ΍ͬͨ͜ͱ • ϗʔΫεͱ೔ϋϜͷ2016೥੒੷ΛηΠόʔϝτϦΫε ࢦඪͰͱʹ͔͘ൺ΂ͯ܏޲Λ୳Δ • ଧऀΛʮಘ఺૑ग़ೳྗʯʮಘ఺Ձ஋ʯΛݩʹධՁ͢Δ • ओʹ΍ͬͨ͜ͱʮͻͨ͢ΒSQLͱάϥϑΛඳ͘ʯ • ຊ౰͸౤ख΋΍Γ͔ͨͬͨͷͰ͕͢,


    ໘ന͍ωλ͕ແ͔ͬͨͨΊׂѪorz
  35. ʲCASE1ʳಘ఺૑ग़ೳྗ

  36. RC27ʹΑΔಘ఺૑ग़ೳྗධՁ • RC27Λ༻͍ͯબखݸਓͷಘ఺૑ग़ೳྗΛධՁ • 1܉Ͱ50ଧ੮Ҏ্ग़৔ͨ͠໺खΛର৅ • ୀஂબख(ཅଲ߯ͳͲ)͸আ֎ • RC27߹ܭ஋Λ྆ٿஂͰൺֱ •

    աڈͷਪҠ,౤ࢿରޮՌ΋ධՁ
  37. RC(Run Created) • ଧܸʹؔ͢Δه࿥ΛҎԼͷΧςΰϦʔʹ෼͚,ͦΕΒΛ࠶ܭࢉ͢Δ͜ͱʹΑΓ,
 ಘ఺Λ૑Γͩ͢ೳྗΛՄࢹԽ͢Δࢦඪ • ग़ྥೳྗ(҆ଧ,࢛ࢮٿ,౪ྥࢮ,ซࡴͳͲ) • ਐྥೳྗ(ྥଧ,౪ྥ,٘ଧ,ࡾৼͳͲ) •

    ग़ྥػձ(ଧ਺,࢛ࢮٿ,٘ඈ,٘ଧ) • RC =ʢग़ྥೳྗA × ਐྥೳྗBʣ/ ग़ྥػձC • RCͷ஋͕େ͖͍=νʔϜͷಘ఺ʹߩݙ͍ͯ͠Δ
  38. RC(SABRΑΓൈਮ) def rc(cls, tb, h, bb, hbp, cs, gidp, sf,

    sh, sb, so, ab, ibb): """ Runs Created :param tb: total bases :param h: hits :param bb: base on ball :param hbp: hit by pitch :param cs: caught stealing :param gidp: ground into duble play :param tb: total bases :param sf: sacrifice fly :param sh: sacrifice hit :param sb: stolen base :param so: strike out :param ab: at bat :param ibb: intentional base on balls :return: (float) run created """ # (ग़ྥೳྗA * ਐྥೳྗB) / ग़ྥػձC a = float(h + bb + hbp - cs - gidp) b = float(tb) + round(0.24 * float(bb + hbp - ibb), 1) + round(0.62 * float(sb), 1)\ + round(0.5 * float(sh + sf), 1) - round(0.03 * float(so), 1) c = float(ab + bb + hbp + sf + sh) a_b = round(a + 2.4 * c) * (b + 3.0 * c) _9c = round(9.0 * c, 1) _09c = round(0.9 * c, 1) rc = round(a_b / _9c - _09c, 2) return rc
  39. RC27(Run Created / 27outs) • RC(Run Created)Λ27Ξ΢τ(≒Ұࢼ߹෼)ʹ׳Βͨ͠ࢦඪ • “9ਓେ୩ͷଧઢ VS

    9ਓΪʔλͷଧઢͲ͕ͬͪڧ͍?”
 తͳ໰୊Λղ͘ʹଧ͚ͬͯͭͷࢦඪ • RC27 =((ग़ྥೳྗA × ਐྥೳྗB) / ग़ྥػձC) / 27outs
 ※େࡶ೺ͳࣜͷߏ଄ • ৄ͍͠ߟ͑ํ͸΢ΟΩϖσΟΞʮRCʢ໺ٿʣʯΛࢀর
  40. RC27(SABRΑΓൈਮ) def rc27(cls, rc, ab, h, sh, sf, cs, gidp):

    """ Runs created 27 :param rc: run created :param ab: at bat :param h: hits :param sh: sacrifice hit :param sf: sacrifice fly :param cs: caught stealing :param gidp: ground into duble play :return: (float) run created 27 """ to = ab - h + sh + sf + cs + gidp rc27 = round(27 * rc / to, 2) return rc27
  41. RC27ධՁ(߹ܭͱਪҠ) ιϑτόϯΫ͕ѹ౗తʹڧͦ͏(খฒ)

  42. Salary/RC27(౤ࢿରޮՌ) ιϑτόϯΫ͕ѹ౗తʹ͔͔ۚͬͯΔ ೔ϋϜ͕Ҋ֎ܦࡁతʂ

  43. ಘ఺૑ग़ೳྗͰΘ͔ͬͨ͜ͱ • ϗʔΫεͷ߈ܸྗ͸Ϡό͍(RC27ϕʔεͰ) • ϗʔΫε͸ٿք۶ࢦͷଧऀΛἧ͑ͨ෼ͷ
 ύϑΥʔϚϯεΛग़͍ͯ͠ΔΑ͏ʹݟ͑Δ • ೔ϋϜ͸͍͍ײ͡ʹ৯Β͍͍͍ͭͯΔ • ౤ࢿରޮՌ͸1,000ສԁҎ্ͷ։͖,೔ϋϜ༏ल

  44. RC/RC27ͷ௕ॴͱ୹ॴ • ʲ௕ॴʳ໺ٿͷಘ఺ߏ଄Λਖ਼֬ʹଊ͍͑ͯΔ(Θ͔Γ΍͍͢) • ग़ྥೳྗɾਐྥೳྗΛ෼͚ͯධՁ • ্هΛग़ྥػձͰׂΔ͜ͱʹΑΓγϯϓϧʹಘ఺ߏ଄Λදݱ • ʲ୹ॴʳʮ৔໘ʯ͕͍࣋ͬͯΔಘ఺ͷՄೳੑΛແࢹ͍ͯ͠Δ •

    ৔໘=Ξ΢τΧ΢ϯτ×૸ऀͷ਺(24௨Γ) • ແࢮ૸ऀແ͠Ͱग़Δ୯ଧͱೋྥଧ,Ͳ͕ͬͪಘ఺ʹܨ͕Δ?
 …ͱ͍͏໰ʹ౴͑ΒΕͳ͍(ϓϨʔ͝ͱͷධՁΛ͍ͯ͠ͳ͍ͨΊ) • ্هͷ୹ॴΛղܾ͢΂͘,ʮಘ఺ظ଴஋ʯͱʮಘ఺Ձ஋ʯΛ༻͍Δ͜ͱʹͨ͠
  45. ಘ఺ظ଴஋ͱಘ఺Ձ஋ • ಘ఺ظ଴஋(Run Expectancy) • ࢼ߹ͷ৔໘͝ͱʹಘ఺ͷੜ·Ε΍͢͞Λ਺஋Խͨ͠΋ͷ • ৔໘(24௨Γ)͝ͱͷʮ૯ಘ఺/৔໘ͷػձ਺ʯΛࢉग़ • ಘ఺Ձ஋(Run

    Value) • ಘ఺ظ଴஋Λݩʹ,ʮϓϨʔ͕ಘ఺ʹରͯ͠ͲΕ͙Β͍Ձ஋͕͋Δ͔ʯΛධՁ͢Δߟ͑ํ • ʲྫʳແࢮҰྥ͔Β୯ଧˠಘ఺ظ଴஋͕0.4→1.0ʹ্ঢˠࠩ෼ͷ0.6͕ಘ఺Ձ஋ʂ • ΋ͪΖΜ,Լ͕Δ͜ͱ΋͋Δ(Ξ΢τΛॏͶΔͱ͔ࡾৼ͢ΔͳͲ) ৄࡉͳղઆ͸ https://ja.wikipedia.org/wiki/Linear_Weights ͋ͨΓʹ͋Γ·͢.
  46. ʲCASE2ʳಘ఺Ձ஋

  47. wRAAΛ༻͍ͯಘ఺Ձ஋ΛධՁ • wOBA(ॏΈ෇͖ग़ྥ཰)Λݩʹ,
 wRAA(ଧऀͷଧܸߩݙ౓)Λࢉग़ • 50ଧ੮Ҏ্ग़৔ͨ͠બखΛର৅ʹ,wRAAΛՄࢹԽ • ୭͕νʔϜͷಘ఺ݯͰ,୭͕଍ΛҾͬு͍ͬͯΔ͔ ͕ҰൃͰΘ͔ΔΑ͏ʹͳΓ·͢ʂʂʂ

  48. wOBA • Weighted On-Base Average(ॏΈ෇͖ग़ྥ཰) • ʮଧऀ͕1ଧ੮͋ͨΓʹͲΕ͚ͩνʔϜͷಘ఺૿Ճʹߩݙ͠ ͔ͨʯΛද͢ࢦඪ • ಘ఺Ձ஋Λݩʹࢉग़͓ͯ͠Γ,܎਺͸ঢ়گ͝ͱͷ਺ࣈͷॏΈ

    ΋͋Δఔ౓ߟྀ͞Ε͍ͯΔ • MLB/NPBڞʹ࠷΋ϝδϟʔͳηΠόʔϝτϦΫεࢦඪͱ͠ ͯ࢖ΘΕ͍ͯΔ
  49. wOBA(SABRΑΓൈਮ) def woba_npb(cls, bb, hbp, _1b, _2b, _3b, hr, ab,

    sf, ibb=0, e_bb=0): """ Weighted on-base average for NPB(wOBA) http://1point02.jp/ :param bb: base on ball :param hbp: hit by pitch :param _1b: single :param _2b: double :param _3b: triple :param hr: home run :param ab: at bat :param sf: sacrifice fly :param ibb: intentional base on balls(default:0) :param e_bb: base on ball for error(default:0) :return: (float) wOBA """ u_bb = round(0.692 * float(bb-ibb), 3) u_hbp = round(float(0.73 * hbp), 3) u_e_bb = round(0.966 * float(e_bb), 3) u_h = round(0.865 * float(_1b), 3) + round(1.334 * float(_2b), 3)\ + round(1.725 * (_3b), 3) + round(2.065 * float(hr), 3) u_pa = round(float(ab + bb - ibb + hbp + sf), 3) return round((u_bb + u_hbp + u_e_bb + u_h) / u_pa, 3)
  50. wRAA • Weighted Runs Above Average(ଧऀͷଧܸߩݙ౓) • ʮฏۉతͳଧऀ͕ಉ͡ଧ੮਺ཱͬͨ৔߹ʹൺ΂ͯ૿΍ͨ͠ಘ ఺ʯΛද͢ࢦඪ •

    wRAA=(ଧऀͷwOBA-ϦʔάwOBA) / wOBAscale * ଧ੮਺ • wOBAͷ୯ҐΛಘ఺ʹ໭͢͜ͱʹΑΓ,ಘ఺ྗΛग़͢ • ໺ٿબखͷ૯߹ࢦඪʮWARʯͷଧܸߩݙ͸wRAAΛݩʹग़͢
  51. wRAA(SABRΑΓൈਮ) def wraa(cls, woba, lg_woba, pa, woba_scale=1.24): """ Weighted Runs

    Above Average(wRAA) http://1point02.jp/ :param woba: weighted on-base average :param lg_woba: weighted on-base average(league average) :param woba_scale: Weighted Runs Above Average scale(default:1.2) :param pa: plate appearance :param woba_scale: weighted on-base average scale(default:1.24) :return: (float) wRAA """ return round(((woba - lg_woba) / woba_scale) * float(pa), 1)
  52. ʲࢀߟʳwOBA/wRAAૣݟද ධՁ X0#" X3"" ૉ੖Β͍͠   ඇৗʹྑ͍  

    ฏۉҎ্   ฏۉ   ฏۉҎԼ   ѱ͍   ඇৗʹѱ͍   ΢ΟΩϖσΟΞʮwOBAʢ໺ٿʣʯΑΓൈਮ
  53. wRAA(ϑΝΠλʔζ2016) େ୩,ϨΞʔυ,੢઒ͦͯ͠ཅ΁ͷґଘ౓ߴ͍ தా͕ࢥͬͨΑΓ௿͍,ݡհ͞Μͱதౡ͞Μ()

  54. wRAA(ϗʔΫε2016) Ϊʔλͷଘࡏײwwwͦͯ͠தଜؤுͬͯΔ,Ϛονͱ಺઒͸༧૝௨Γ ೋ༡͓ؒΑͼัखͰಘ఺Ձ஋తʹଛͯ͠Δ

  55. ಘ఺Ձ஋ͰΘ͔ͬͨ͜ͱ • ϗʔΫεͷ߈ܸྗ͸Ϊʔλʹґଘ͍ͯ͠Δ • Ͱ΋தଜ,Ϛον,಺઒΋͗͢͢͝Δ • ೔ϋϜ͸େ୩,੢઒΁ͷґଘ౓͕ߴ͍ • ྆νʔϜڞʹγϣʔτ͕ಘ఺Ձ஋ΛԼ͛ͯΔ

  56. ಘ఺Ձ஋͔ΒΘ͔Δ/Θ͔Βͳ͍ • ʲΘ͔ΔʳνʔϜͷಘ఺ݯͱґଘ౓ • ϗʔΫεɿΪʔλ,தଜ,Ϛον,಺઒ • ೔ϋϜɿେ୩,੢઒,ϨΞʔυ,ཅଲ߯(ୀஂ) • ʲΘ͔Βͳ͍ʳಘ఺Ձ஋ϚΠφε=͍Βͳ͍,Ͱ͸ͳ͍ •

    ࠓٶ,தౡ͸कඋͰಘ఺Ձ஋ϚΠφε෼Λฦ͍ͯ͠Δ • (कΕΔҰྥख)தాᠳ͞Μ΋ಉ͡(ry
  57. ςʔϚʮະདྷʯ

  58. ະདྷ #ͱ͸

  59. ϗʔΫε͕ࠓ೥༏উ͢Δʹ͸? • Ϊʔλ͕ոզ͢Δ͜ͱແ͘ϑϧग़৔͢Δ • ಘ఺ݯͰ͋Γ,ґଘ౓͕ߴ͍ • ڈ೥ͷ༻ʹոզͨ͠Γ͢Δ͚ͩͰ૬౰ϚΠφε • ೋྥखෆࡏ໰୊Λղܾ͢Δ •

    ೋྥͷಘ఺ߩݙ͕ݢฒΈϚΠφε • Ϝω͞Μ͕Ͳ͏ߩݙ͢Δ͔͕ϙΠϯτ͔ͭݟ΋ͷʂ
  60. ·ͱΊ • ͦΒʢಘ఺Ձ஋ʹΑΔಘ఺ྗධՁ͸ʣ
 ͦ͏ʢνʔϜͷಘ఺ݯͱ΢ΟʔΫϙΠϯτؙ͕ݟ͑Ͱ໘ന͍ʹʣ
 Αɹʢܾ·͍ͬͯΔ͡Όͳ͍͔ʣ • ϗʔΫε͞Μ͸Ͳ͏ͧΪʔλ͞ΜʹոզΛͤ͞ͳ͍Α͏ʹؾΛ͚ͭΑ͏ • ೔ϋϜ͸,,,େ୩ᠳฏ཭୤ͷ࣌఺Ͱ͓࡯͠(ͭΒ͍) •

    ָఱ͕Ϧʔυ͠·ͬͯ͘Δ͕ϗʔΫε͕͍ͣΕ௥͍ͭ͘ͷͰ͸? • ೔ϋϜ͸͓ͱͳ͘͠3ணૂ͍Ͱߦ͜͏(਒͑੠)
  61. એ఻ (গ͚ͩ͠)

  62. None
  63. Retty #ͱ͸ • ໊࣮ޱίϛͱਓͷͭͳ͕ΓΛ ௨ͯ͡ҿ৯ళΛ୳͢͜ͱ͕ग़ དྷΔαʔϏε • ΞϓϦͱWeb྆ํ͋Γ·͢
 ੋඇDLͯ͠Ͷʂˠ •

    Python͸σʔλαΠΤϯε
 &Ұ෦ϓϩμΫτͰ࢖ͬͯ·͢
  64. εϙϯαʔ΍Γ·͢ʂ

  65. Python × Retty • ࠓޙ΋ΠϕϯτεϙϯαʔͳͲΛ௨ͯ͡ίϛϡχςΟʔΛ੝Γ ্͍͖͛ͯ·͢ʂ • σʔλαΠΤϯε͚ͩͰͳ͘,ϓϩμΫτνʔϜ΋PythonԽΛ ਐΊ͍ͯ·͢ •

    ڵຯ͕͋Δํ͸্ژͷࡍʹRettyʹ༡ͼʹདྷ͍ͯͩ͘͞ʂ • http://corp.retty.me/ • https://www.wantedly.com/companies/retty
  66. ήʔϜηοτʂʂʂ ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠&PyCon JP 2017Ͱ͓ձ͍͠·͠ΐ͏ʂ Shinichi Nakagawa(Twitter/Facebook/hatena:@shinyorke)

  67. ʲAppendixʳwRAAશ෦ݟͤ·͢ ঺հͨ͠೔ϋϜɾϗʔΫεҎ֎ͷશ10ٿஂ ͔ͤͬ͘ࢉग़ͨ͠ͷͰੇධͱڞʹ঺հ

  68. wRAA(ઍ༿ϩος2016) ֯த͞Μ΁ͷѹ౗తґଘ౓΍͹͍ σεύΠω͕ൈ͚ͨ෼ΛͲ͜Ͱิర͢Δ͔͕ϙΠϯτ

  69. wRAA(ϥΠΦϯζ2016) ઙଜͷߩݙ౓͕ߴׂ͍ʹաখධՁ͞Ε͍ͯΔ(ͭΒ͍) ଧܸ͚ͩͰݟͨΒۜ࣍࿠͸ͬ͞͞ͱ৿༑࠸ʹ(ry

  70. wRAA(Πʔάϧε2016) ΢Οʔϥʔ,ϖήʔϩͱ͍ͬͨॿͬਓʹґଘ͗͢͠ ໜ໦͕ؤுΕ͹͔ͳΓ໘നͦ͏&ౢ͞Μͷߩݙૉ੖Β͍͠

  71. wRAA(όϑΝϩʔζ2016) ࢳҪՅஉʹґଘ͍ͯͨ͠෦෼ΛͲ͜Ͱิర͢Δ͔͕ϙΠϯτ ٢ాਖ਼ঘ͓Αͼॿͬਓ͕Ͳ͜·Ͱ৳ͼΔָ͔͠Έ

  72. wRAA(޿ౡ2016) શମతʹૉ੖Β͍͠ηϦʔάνϟϯϐΦϯ कඋߩݙؚΊ,ླ໦੣໵ͱ٠஑ྋհ͸όέϞϊతͳධՁΛ༩͑ͯྑ͍

  73. wRAA(ڊਓ2016) ࡔຊ༐ਓ͋ͬͯͷڊਓʂͱ͍͏݁Ռ Ѩ෦͕Ұྥస޲ґཔ,ϗϯτʹัख͕݀ʹͳͬͯΔ(୭͕ͱ͸ݴΘͳ͍)

  74. wRAA(ϕΠελʔζ2016) ౵߳Յஐʹґଘ͗͢͠໰୊͋Δ͕֎໺͸׬ᘳ ౵͕߳ൈ͚ͨΒ஍ࠈ͔͠ແ͍&಺໺Ͱ΋ͬͱఈ্͛Λʂ

  75. wRAA(ࡕਆ2016) ෱ཹ޹հ&ݪޱจਔͷߩݙ౓͸कඋؚΊഥखʂʂ ௗ୩͞Μ͸ಘ఺Ձ஋Ͱ΋଍ΛҾͬுͬͯΔͷ͕൵͍͠

  76. wRAA(ϠΫϧτ2016) ࢁా఩ਓ༷͋ͬͯͷϠΫϧτ,ͱ͍͏݁Ռ͕೗࣮ʹग़͍ͯΔ େ͖ͳϚΠφε͸ແ͍͕,ിࢁͱ઒୺͸ͥͻ݈߁తʹ୔ࢁࢼ߹ʹग़ͯ΄͍͠

  77. wRAA(υϥΰϯζ2016) ϏγΤυɾฏాɾେౡͷ֎໺ਞ͸จ۟ͳ͠ େ͖͘མͪࠐΜͰ͍Δߥ໦͸͡Ί಺໺ͷ੔ཧ͕࠷༏ઌ