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

Hivemallを使ってSQLで機械学習

babahr
January 16, 2020

 Hivemallを使ってSQLで機械学習

Data Gateway Talk vol.5のLT登壇資料です.
(イベントURL https://data-gateway-talk.connpass.com/event/155457/)

babahr

January 16, 2020
Tweet

Other Decks in Programming

Transcript

  1. ࠓ೔ͷ಺༰ ͓఻͍͑ͨ͜͠ͱ w )JWFNBMM͸Ͳ͜ͰͲͷΑ͏ʹ࢖͏ͷ͔ w )JWFNMMΛ࢖͏ͱԿ͕خ͍͠ͷ͔ ࿩͞ͳ͍͜ͱ w )JWFNBMMͰ࣮૷͞Ε͍ͯΔΞϧΰϦζϜͷৄࡉ w

    )JWFNBMM EJHEBHͷৄࡉͳ࢖͍ํ ɹ)JWFNBMM ΍EJHEBH ͷ࢖͍ํʹؔͯ͠͸ ɹɾެࣜυΩϡϝϯτ ɹɾެࣜHJUIVCͷ࣮૷ྫ ɹɾ։ൃऀͷ༉Ҫ͞Μͷॻ͔Ε͍ͯΔRJJUB ɹɹˢݸਓతʹ͔ͳΓΦεεϝ ɹ౳Λ࢝Ίɺ༗༻ͳهࣄ͕͋Γ·͢ͷͰͦͪΒޚཡ͍ͩ͘͞ 14% |❚❚❚ | 03/22
  2. ࣗݾ঺հ ˗ ໊લɿഅ৔͸Δ͔ ˗ ग़਎ɿ૯߹ݚڀେֶӃେֶఱจՊֶઐ߈
 ଠཅܥ֎࿭੕ ׊৭ᛙ੕ ࿭੕࣭ྔఱମ ˗ σʔλαΠΤϯςΟετΛ͍ͯ͠Δ


    ΫϥΠΞϯτاۀͷΦ΢ϯυϝσ ΟΞͷձһσʔλ΍Ξϯέʔτ σʔλͷ෼ੳͳͲ 18% |❚❚❚❚ | 04/22 גࣜձࣾϒϨΠϯύουʮ "*ʢϓϥεΤʔΞΠʣʯ΢ΣϒαΠτΑΓ
  3.  ϒϨΠϯύου നۚ୆ΦϑΟε ͜͜ 27% |❚❚❚❚❚❚ | 06/22 ςʔϚ ෺ཧֶʷػցֶश

    ಺༰ ɾػցֶशΛ࢖ͬͨ෺ཧֶ෼໺ͷݚڀ঺հ ɾ෺ཧग़਎σʔλαΠΤϯςΟετͷ͓࢓ࣄͷ࿩ ɾ࿦จ঺հ࿮ ର৅ऀ ɾ෺ཧ͕޷͖ͳσʔλΞφϦετ σʔλαΠΤϯςΟετ .-ΤϯδχΞ ɾ෺ཧ෼໺ͷݚڀऀ ɾ෺ཧֶઐ߈ͷֶੜ
  4. +----------+----------+ | item_id | order_id | +----------+----------+ | 1 |

    1 | | 2 | 1 | | 3 | 2 | +----------+----------+ 55% |❚❚❚❚❚❚❚❚❚❚❚❚ | 12/22
  5. +----------+----------------------+ | model_id | model | +----------+----------------------+ | 1 |L?jrjk,O5v%zkfspel……

    | +----------+----------------------+ 68% |❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚ | 15/22
  6. σʔλϚʔτ xgb_input ֶश༻ΫΤϦ SELECT train_xgboost(features, label) as (model_id, model) FROM

    (SELECT features ,label FROM xgb_input cluster by rand(43) -- shuffle ) shuffled; xgb_model Ϟσϧ model_id Model 0 L?jrjk,O5v%z|kfspel…… 1 L?jrjk>PS;fkjsa^8~6|…… 2 lsa;p0”>02qJOel~2=*…… ộ ộ xgb_pred ༧ଌ݁Ռ ༧ଌ༻ΫΤϦ SELECT rowid, majority_vote(cast(predicted as int)) as label FROM ( SELECT xgboost_predict_one(rowid, dense_features, model_id, model) as (rowid, predicted) FROM xgb_model l LEFT OUTER JOIN xgb_input r ) t GROUP BY rowid; row_id Label 0 0 1 2 2 1 ộ ộ Ϟσϧ΍༧ଌ݁Ռ͸ςʔϒϧͰ؅ཧ 77% |❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚ | 17/22
  7. ྫ σδλϧϚʔέςΟϯάྖҬʹ͓͚Δ
 ػցֶशγεςϜ૊ΈࠐΈ ֤ج൫γεςϜ σʔλϕʔε &$ ސ٬৘ใ 8FC ෼ੳ༻؀ڥ Ճ޻ɾసૹ

    લॲཧɹˠɹֶशɹˠɹਪ࿦ Ճ޻ɾసૹ &$ ׆༻ઌ ؀ڥΛ༻ҙ͢ΔϦιʔε Ճ޻ɾసૹͷ࣮૷ ӡ༻ͷίετ 91% |❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚ | 20/22
  8. ֤ج൫γεςϜ σʔλϕʔε &$ ސ٬৘ใ 8FC લॲཧɹˠɹֶशɹˠɹਪ࿦ &$ ׆༻ઌ ✓σʔλϕʔε಺෦ͰػցֶशͷҰ࿈ͷϑϩʔ͕׬݁ ✓σʔλ࿈ܞͷखؒΛলུՄೳ

    ӡ༻໨ઢͰ͸େ͖ͳϝϦοτ 95% |❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚ | 21/22 )JWF͕࢖͑Δ ৔߹ ෼ੳ༻؀ڥ͕ෆཁ
  9. ·ͱΊ w )JWFNBMMͱ͍͏)JWF2-ϕʔεͰॻ͚ΔػցֶशϥΠϒϥϦ͕͋Γɺ σʔλసૹϓϩηε͕ෆཁͳ఺ɺࠓ͋Δ؀ڥͷ··࣮૷Ͱ͖Δ఺͕େ ͖ͳϝϦοτ w )JWF͕࢖͑Δ؀ڥͰػցֶशγεςϜΛ؆୯ʹࢼ͍ͨ͠৔߹ɺ )JWFNBMM͕Φεεϝ w ৮Ε·ͤΜͰ͕ͨ͠

    ࢖͑ΔΞϧΰϦζϜ΋ൺֱతଟذʹΘͨΔ )JWF͕࢖͑Δ؀ڥPS5SFBTVSF%BUBಋೖاۀͰ
 ͓࢓ࣄ͞Ε͍ͯΔ%4ͷํ͸ͥͻ͓ࢼ͠Λʂ 100% |❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚| 22/22