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

BigQuery と BigQuery ML

jewel12
November 20, 2018
95

BigQuery と BigQuery ML

jewel12

November 20, 2018
Tweet

Transcript

  1. #2ར༻·Ͱͷงғؾ #JH2VFSZ (PPHMF $MPVE 4UPSBHF 'JSFCBTF "OBMZUJDT -PDBM 4UPSBHF FH$47

    'MVFOUE ɾ &NCVML 8FC$POTPMF (PPHMF 4QSFBETIFFU (PPHMF %BUBTUVEJP +VQZUFS /PUFCPPL ʜ ʜ
  2. Ϟσϧ࡞੒ CREATE MODEL `bqml_tutorial.sample_model` OPTIONS(model_type='logistic_reg') AS SELECT IF(totals.transactions IS NULL,

    0, 1) AS label, IFNULL(device.operatingSystem, "") AS os, device.isMobile AS is_mobile, IFNULL(geoNetwork.country, "") AS country, IFNULL(totals.pageviews, 0) AS pageviews FROM `bigquery-public- data.google_analytics_sample.ga_sessions_*` WHERE _TABLE_SUFFIX BETWEEN '20160801' AND '20170630'
  3. Ϟσϧ࡞੒ CREATE MODEL `bqml_tutorial.sample_model` OPTIONS(model_type='logistic_reg') AS SELECT IF(totals.transactions IS NULL,

    0, 1) AS label, IFNULL(device.operatingSystem, "") AS os, device.isMobile AS is_mobile, IFNULL(geoNetwork.country, "") AS country, IFNULL(totals.pageviews, 0) AS pageviews FROM `bigquery-public- data.google_analytics_sample.ga_sessions_*` WHERE _TABLE_SUFFIX BETWEEN '20160801' AND '20170630' ϩδεςΟοΫճؼͷϞσϧΛ࡞Δ ༧ଌͷϥϕϧʢܾࢉͨ͠PSͯ͠ͳ͍ʣ ༧ଌϥϕϧ͸MBCFMΧϥϜͰ΋015*0/4Ͱ΋ ࢦఆͰ͖Δ 4&-&$5ͨ͠σʔλͰֶश 4&-&$5͍ͯ͠Δ֤ΧϥϜΛύϥϝʔλͱͯ͠νϡʔχϯά͢Δ
  4. ϞσϧͷධՁ #standardSQL SELECT * FROM ML.EVALUATE(MODEL `bqml_tutorial.sample_model`, ( SELECT IF(totals.transactions

    IS NULL, 0, 1) AS label, IFNULL(device.operatingSystem, "") AS os, device.isMobile AS is_mobile, IFNULL(geoNetwork.country, "") AS country, IFNULL(totals.pageviews, 0) AS pageviews FROM `bigquery-public- data.google_analytics_sample.ga_sessions_*` WHERE _TABLE_SUFFIX BETWEEN '20170701' AND '20170801')) .-&7"-6"5& ͰϞσϧΛධՁ͢Δ ධՁσʔλ͸Ϟσϧ࡞੒࣌ʹ࢖ͬͨ೔෇ͱ͸ҧ͏΋ͷΛར༻͍ͯ͠Δ ֤ࢦඪͷݟํ͸νϡʔτϦΞϧͷεςοϓ
  5. ϞσϧΛ࢖ͬͯ༧ଌ #standardSQL SELECT country, SUM(predicted_label) as total_predicted_purchases FROM ML.PREDICT(MODEL `bqml_tutorial.sample_model`,

    ( SELECT IFNULL(device.operatingSystem, "") AS os, device.isMobile AS is_mobile, IFNULL(totals.pageviews, 0) AS pageviews, IFNULL(geoNetwork.country, "") AS country FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*` WHERE _TABLE_SUFFIX BETWEEN '20170701' AND '20170801')) GROUP BY country ORDER BY total_predicted_purchases DESC LIMIT 10 wࠃ͝ͱͷਫ਼ࢉ׬ྃ਺Λ༧ଌ w.-13&%*$5ؔ਺ͷ4&-&$5Ͱೖྗ w݁Ռ͸QSFEJDUFE@MBCFMʹPSͰೖΔ wQSFEJDUFE@MBCFM@DPMVNO@OBNFͱ͍͏໋໊نଇ
  6. w ೥ͷهࣄͳͷͰࠓ͸ҧ͏͔΋ w IUUQTDMPVEHPPHMFDPNCMPHQSPEVDUTHDQCJHRVFSZ VOEFSUIFIPPE w ྻࢦ޲%#ͱΫΤϦͷ෼ׂ౷࣏ w ԣʹ͢Ε͹͢Δ΄Ͳ଎͍ͷͰɺຊ౰ʹେྔͷϦιʔεΛ࢖͑Δ (PPHMFͳΒͰ͸ͷαʔϏε

    w %SVNFMΫΤϦ࣮ߦΤϯδϯ w ΫΤϦΛ෼ׂͯ͠ॲཧ͠ɺ࠷ऴతʹ૊Έ্͛Δ·Ͱ w $PMPTTVT෼ࢄετϨʔδ w ΧϥϜ୯ҐͰσʔλΛѹॖ w #PSHΫϥελϚωʔδϟ w ਺ेສ୆ͷϚγϯͰಈ࡞͢ΔΫϥελ w Ϛγϯ͕མͪͯ΋େৎ෉ w +VQJUFSωοτϫʔΫ w 1FUBCJUTFDͷόϯυ෯Λ࣋ͭωοτϫʔΫ w ສ୆ͷϚγϯ͕(CTͰ΍ΓͱΓͰ͖Δ w %SFNFMͷ֤֊૚ؒ΍-FBG/PEFTͱ$PMPTTVTͰͷσʔλ ͷ΍ΓͱΓΛߴ଎ԽͰ͖Δ