Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
spark.ml の API で XGBoost を扱いたい!#shokaispark
Search
KOMIYA Atsushi
May 11, 2016
Programming
3
4.5k
spark.ml の API で XGBoost を扱いたい!#shokaispark
『詳解 Apache Spark』出版記念イベントでの発表資料です。
http://connpass.com/event/30375/
KOMIYA Atsushi
May 11, 2016
Tweet
Share
More Decks by KOMIYA Atsushi
See All by KOMIYA Atsushi
#JJUG Java における乱数生成器とのつき合い方
komiya_atsushi
5
5.1k
#JJUG Fork/Join フレームワークを効率的に正しく使いたい
komiya_atsushi
0
440
[#JSUG] SmartNews における container friendly な Spring Boot アプリケーション開発
komiya_atsushi
1
11k
Java のデータ圧縮ライブラリを極める #jjug_ccc #ccc_c7
komiya_atsushi
4
4.6k
#devsumi 自然言語処理・機械学習によるファクトチェック業務の支援
komiya_atsushi
1
4.2k
SmartNews Ads における機械学習の活用とその運用 #mlops
komiya_atsushi
3
19k
GBDT によるクリック率予測を高速化したい #オレシカナイト vol.4
komiya_atsushi
5
1.3k
Maven central repository の artifact をランキングする #渋谷java
komiya_atsushi
0
1.2k
確率的データ構造を Java で扱いたい! #JJUG
komiya_atsushi
6
2.2k
Other Decks in Programming
See All in Programming
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
290
メルカリ ハロ アプリの技術スタック
atsumo
2
410
Go製CLIツールGatling Commanderによる負荷試験実施の自動化
okmtz
3
680
C#および.NETに対する誤解をひも解く
ymd65536
0
240
Modern Functional Fluent CFML REST by Luis Majano
ortus24
0
140
DevFest Android in Korea 2024 - 안드로이드의 문단속 : 앱을 지키는 암호화 이야기
mdb1217
1
140
Cloud Adoption Framework にみる組織とクラウド導入戦略
tomokusaba
2
420
コードレビューと私の過去と未来
jxmtst
0
230
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
0
160
2024-10-02 dev2next - Application Observability like you've never heard before
jonatan_ivanov
0
160
M5Stack に色々な M5ユニットをつないで扱う為の新たなアプローチ
gob
0
200
フロントエンドの現在地とこれから
koba04
10
4.4k
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
41
9.2k
Automating Front-end Workflow
addyosmani
1365
200k
Infographics Made Easy
chrislema
239
18k
How GitHub Uses GitHub to Build GitHub
holman
473
290k
For a Future-Friendly Web
brad_frost
174
9.3k
Code Reviewing Like a Champion
maltzj
519
39k
Art, The Web, and Tiny UX
lynnandtonic
296
20k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.8k
Web development in the modern age
philhawksworth
205
10k
Transcript
spark.ml ͷ API Ͱ XGBoost Λѻ͍͍ͨʂ 2016-05-11 ʰৄղ Apache Sparkʱग़൛ه೦Πϕϯτ
KOMIYA Atsushi (@komiya_atsushi)
͓·͑ͩΕΑ
KOMIYA Atsushi @komiya_atsushi
Today’s topic
on
XGBoost • ޯϒʔεςΟϯάͷ࣮ͷҰͭ • ܾఆʹର͢ΔޯϒʔεςΟϯάɺ MLlib Ͱ GBTClassifier / GBTRegressor
ͱ ࣮ͯ͠͞Ε͍ͯΔ • ༧ଌਫ਼ͷߴ͞ͳͲ͔ΒɺKaggler ͳํʑΛ த৺ʹਓؾ͕͋ΔʢͬΆ͍ʣ
spark.ml ͷ API Ͱɺ XGBoost Λ Spark ্Ͱ ѻ͍͍ͨʂ
spark.ml ͷ API Ͱѻ͑Δͱ… • spark.ml ͕ఏڙ͢Δ֤छػೳΛ༗ޮ׆༻Ͱ͖Δ • ಛநग़ɾมɾબ •
ύϥϝʔλͷάϦουαʔν • ύΠϓϥΠϯ • ަࠩݕূ… ͳͲ
͜ͷൃදͰ͓͢Δ͜ͱ • XGBoost on Spark ͷݱঢ় • spark.ml ͷ API
ͰػցֶशΞϧΰϦζϜΛ ࣮͢ΔࡍͷϙΠϯτ • ಛʹΠϯλϑΣʔε෦ʹண͢Δ
XGBoost & Spark
XGBoost on Spark • Spark ্Ͱ XGBoost Λ͓͏ͱ͢Δͱɺ ݱঢ়Ͱબࢶ 2
ͭ • SparkXGBoost • xgboost4j-spark
SparkXGBoost • https://github.com/rotationsymmetry/sparkxgboost • XGBoost ͱಉ͡ޯϒʔεςΟϯάπϦʔΛɺSpark ͚ ʹ pure Scala
Ͱ࣮͍ͯ͠Δ • Spark packages ʹొ͞Ε͍ͯΔ • ΦϦδφϧͷ XGBoost ʹͲ͜·Ͱ࣮ͳ࣮ͳͷ͔ෆ໌ • ver 0.6 ·ͰͷϩʔυϚοϓ͕͋Δ͕ɺ։ൃ͕׆ൃͰͳ͍ • ࠷ޙͷίϛοτࡢ 11 ݄ɺver 0.2
xgboost4j-spark • DMLC ͕ఏڙ͢Δެࣜͷ Spark integration • ͨͩ͠ɺDataFrame ʹରԠ͍ͯ͠ͳ͍ •
XGBoost ຊମͷ git ϦϙδτϦ্Ͱϝϯς͞Ε͍ͯΔ • ֶश͓Αͼ༧ଌͷ۩ମతͳॲཧɺJNI ܦ༝Ͱ C++ ࣮ʹ͓ͤ • ֶश࣌ͷϫʔΧʔؒͷ௨৴ʹ Rabit Λར༻͍ͯ͠Δ • Maven central ʹొ͞Ε͍ͯͳ͍ • ར༻͢ΔʹྑϏϧυඞਢ
ࠓճ… • SparkXGBoost ͷΑ͏ʹɺXGBoost Λֶशث ؚΊͯ pure Scala Ͱ࠶࣮͢Δͷϋʔυϧ ͕ߴ͍
• xgboost4j-spark ͕ࢀর͢Δ xgboost4j Λ ϕʔεʹɺspark.ml ͷ API Ͱϥοϓͯ͠ΈΔ
spark.ml internals (ΏΔ;Θ)
spark.ml ͷ࣮ΛಡΉ • spark.ml ʹ͓͚ΔػցֶशΞϧΰϦζϜͷ ࣮͓࡞๏ΛΔʹͲ͏ͨ͠ΒΑ͍͔ʁ • MLlib ͕ఏڙ͢Δ֤छΞϧΰϦζϜͷ࣮Λ ಡΉͷ͕Ұ൪ͷۙಓ
spark.ml ͷ࣮ΛಡΉ • ࣮ΛಡΉͷʹ͓͢͢ΊͳػցֶशΞϧΰϦζϜ • ϩδεςΟοΫճؼ • LogisticRegression / LogisticRegressionModel
• ܾఆ (ྨ) • DecisionTreeClassifier / DecisionTreeClassificationModel • ܾఆ (ճؼ) • DecisionTreeRegressor / DecisionTreeRegressionModel
spark.ml ʹ͓͚Δػցֶशͷ࣮ • ػցֶशΞϧΰϦζϜͷֶशثɺΛḷΔͱ Estimator Ϋϥεʹߦ͖ண͘ • ֶशثʹΑͬͯಘΒΕΔ༧ଌϞσϧɺΛḷΔͱ Transformer Ϋϥεʹߦ͖ண͘
• ຊॻͷ pp.217-218 Λࢀর • ͨͩ͠ͲͪΒ Estimator Transformer Λ extends ͍ͯ͠ΔͱݶΒͳ͍
ֶशثͷΫϥε֊ &TUJNBUPS 1SFEJDUPS $MBTTJpFS 1SPCBCJMJTUJD$MBTTJpFS ճؼΞϧΰϦζϜͷଟ͘ 1SFEJDUPSΛFYUFOET͍ͯ͠Δ ྨΞϧΰϦζϜͷଟ͘ 1SPCBCJMJTUJD$MBTTJpFSΛFYUFOET͍ͯ͠Δ
༧ଌϞσϧͷΫϥε֊ 5SBOTGPSNFS 1SFEJDUJPO.PEFM $MBTTJpDBUJPO.PEFM 1SPCBCJMJTUJD$MBTTJpDBUJPO.PEFM 1SFEJDUPSʹରԠ͢Δ ༧ଌϞσϧͷΫϥεͱͳΔ 1SPCBCJMJTUJD$MBTTJpFSʹରԠ͢Δ ༧ଌϞσϧͷΫϥεͱͳΔ
ֶशثͱ༧ଌϞσϧͷ࣮
Predictor Ϋϥε • ΧϥϜ • label: ਖ਼ղϥϕϧΛ࣋ͭΧϥϜ • features: ಛϕΫτϧΛ࣋ͭΧϥϜ
• prediction: ༧ଌ͞Εͨϥϕϧ͕ઃఆ͞ΕΔΧϥϜ • ϝιου • train (நϝιου): ֶशॲཧΛ࣮͢Δ • extractLabeledPoints: DataFrame ͔Β RDD[LabeledPoint] Λੜͯ͘͠ΕΔϝιου
Classifier Ϋϥε • ΧϥϜ • rawPrediction: ༧ଌϞσϧ͕ੜͨ͠ੜͷ ͕ઃఆ͞ΕΔΧϥϜ • ༧ଌϥϕϧɺ͜ͷΛجʹٻΊΒΕΔ
ProbabilisticClassifier Ϋϥε • ΧϥϜ • probability: (ೋྨͰ͋Ε) ਖ਼ղϥϕϧ͕ 1 Ͱ͋Δͱ༧ଌ͞ΕΔ͕֬ઃఆ͞ΕΔΧϥϜ
• ύϥϝʔλ • threshold: ༧ଌ֬ (probability ΧϥϜ) ʹج͍ͮ ͯ 0/1 ʹৼΓ͚Δࡍͷ͖͍͠
PredictionModel Ϋϥε • ϝιου • transform: transformImpl ϝιουΛݺͼग़͚ͩ͢ • transformImpl:
༩͑ΒΕͨ DataFrame ͷͦΕͧΕ ͷߦ͝ͱʹ predict ϝιουΛݺͼग़͢ • predict (நϝιου): ༩͑ΒΕͨಛϕΫτϧ͔ Β༧ଌ݁ՌΛੜ͢ΔॲཧΛ࣮͢Δ
ClassificationModel Ϋϥε • ϝιου • transform: predict ϝιου predictRaw &
raw2Prediction ϝιουΛݺͼग़ͯ͠༧ଌ݁ՌΛٻΊΔ • predict: predictRaw ϝιουͷ݁ՌΛ raw2Prediction ʹ͠ ͯ༧ଌϥϕϧΛฦ͢ • predictRaw (நϝιου): ༧ଌϞσϧΛ༻͍ͯੜͷ༧ଌΛ ฦ͢ॲཧΛ࣮͢Δ • raw2Prediction (நϝιου): ༧ଌϞσϧ͕ੜͨ͠ੜͷ༧ ଌ͔ΒϥϕϧΛ༧ଌॲཧΛ࣮͢Δ
ProbabilisticClassificationModel Ϋϥε • ϝιου • predictRaw (நϝιου): ClassificationModel ʹಉ͡ •
raw2ProbabilityInPlace (நϝιου): ੜͷ༧ଌ͔Β༧ଌ ֬ʹม͢ΔॲཧΛ࣮͢Δ • predictProbability: predictRaw ϝιουͷ݁ՌΛ raw2ProbabilityInPlace ϝιουʹͯ͠༧ଌ֬ʹม͢Δ • probability2Prediction: ༧ଌ͔֬Β༧ଌϥϕϧΛฦ͢ • raw2Prediction: ੜͷ༧ଌ͔Β༧ଌϥϕϧΛฦ͢
ֶशثɾ༧ଌϞσϧͷ࣮ͷϙΠϯτ (1) • ྨΞϧΰϦζϜͱճؼΞϧΰϦζϜͰ࣮ΫϥεΛ ͚Α͏ • MLlib ͰɺϥϯμϜϑΥϨετޯϒʔεςΟ ϯάπϦʔͷΑ͏ʹɺྨʹճؼʹ͑ΔΞϧ ΰϦζϜͦΕͧΕͷ࣮Ϋϥε͕༻ҙ͞Ε͍ͯΔ
• e.g. GBTClassifier and GBTRegressor
ֶशثɾ༧ଌϞσϧͷ࣮ͷϙΠϯτ (2) • ྨΞϧΰϦζϜͷ࣮ • ֶशثͷ࣮Ϋϥε ProbabilisticClassifier Λ extends ͠Α͏
• ༧ଌϞσϧͷ࣮Ϋϥε ProbabilisticClassificationModel Λ extends ͠Α͏ • (ςϯϓϨతͳϝιουͷ࣮Λআ͚) predictRaw, raw2probabilityInPlace ϝιουΛ࣮͢Δ͚ͩͰࡁΉ
ֶशثɾ༧ଌϞσϧͷ࣮ͷϙΠϯτ (3) • ճؼΞϧΰϦζϜͷ࣮ • ֶशثͷ࣮Ϋϥε Predictor Λextends ͠Α͏ •
༧ଌϞσϧͷ࣮Ϋϥε PredictionModel Λ extends ͠Α͏ • predict ϝιουΛ࣮͢Δ͚ͩͰࡁΉ
ύϥϝʔλ
spark.ml ʹ͓͚Δύϥϝʔλ • ػցֶशʹϋΠύʔύϥϝʔλͷνϡʔχϯά͕ ͖ͭͷ • spark.ml ͰάϦουαʔνͷػೳΛఏڙ͍ͯ͠Δ • spark.ml
ͰػցֶशΞϧΰϦζϜΛ࣮͢Δࡍɺ ύϥϝʔλνϡʔχϯάͰ͖ΔΑ͏ߟྀ͕ඞཁ
ύϥϝʔλͷ࣮ྫ trait XGBoostGeneralParams extends Params { final val booster: Param[String]
= new Param(this, "booster", // ύϥϝʔλ໊ "which booster to use, can be gbtree or gblinear.", // આ໌ // ύϥϝʔλʹର͢ΔόϦσʔγϣϯϧʔϧ ParamValidators.inArray(Array("gbtree", "gblinear"))) // setter, getter Λ༻ҙ͢Δ def setBooster(value: String): this.type = set(booster, value) def getBooster: String = $(booster) // σϑΥϧτΛઃఆ͢Δ setDefault(booster, "gbtree") }
ύϥϝʔλͷ࣮ϙΠϯτ (1) • ύϥϝʔλΛఆٛ͠Α͏ • ܕ • Param, DoubleParam, IntParam,
FloatParam, LongParam… • ύϥϝʔλ໊ • આ໌ • όϦσʔγϣϯ • ParamValidators ͕ఏڙ͢ΔϑΝΫτϦϝιουΛར༻͢Δ
ύϥϝʔλͷ࣮ϙΠϯτ (2) • getter / setter Λ༻ҙ͠Α͏ • σϑΥϧτΛઃఆ͠Α͏ •
͜ͷ͋ͨΓςϯϓϨతͳ࣮ʹͳΔ
spark.ml-friendly XGBoost
xgboost-dataframe-prototype • https://github.com/komiya-atsushi/xgboost- dataframe-prototype • repo ໊ʹ͋Δͱ͓ΓɺϓϩτλΠϓͰ͢ • ͝ར༻͍ͨͩ͘ࡍ͝ҙΛ •
ֶश࣌ͷࢄॲཧ͍ͯ͠·ͤΜ • Rabit ͷ API ΛѲ͢Δඞཁ͕͋ΔͷͰ…
·ͱΊ
·ͱΊ • XGBoost Λࡐʹɺspark.ml ͷ API Ͱػցֶश ΞϧΰϦζϜΛ࣮͢ΔϙΠϯτΛ͓͠·ͨ͠ • ֶशثɾ༧ଌϞσϧͷΫϥε
• ύϥϝʔλ • Έͳ͞·ͷ Spark ্Ͱͷػցֶशͷ࣮ͷࢀߟ ʹͳΕ͍Ͱ͢
Thank you!