SlideShare a Scribd company logo
Developers
         Summit




                          アドテク・ターゲティング技術
                             〜Pig, Mahout, KVS〜


                                                                 太田祐一
      15-C-7                                                  株式会社オウルデータ
                                                               代表取締役社長 兼
      #devsumiC                                   データマイニングエンジニア

                            Developers Summit 2013 Action !

Friday, February 15, 13
Developers
         Summit

                          自己紹介


             太田祐一(おおたゆういち)
        • 最近子供が生まれてイクメンに
        • もともとは証券会社員
        • 独立して失敗
        • スペイシーズにData mining engineerとして拾ってもらう
        • DMP事業が独立して新会社設立(オウルデータ)→代表に



                          Developers Summit 2013 Action !   2

Friday, February 15, 13
Developers
         Summit




       とにかくデータを集めて触ってみよう!




                          Developers Summit 2013 Action !

Friday, February 15, 13
Developers
         Summit

                   とにかくデータを集めて触ってみよう
     MY     RECOMMEND     NEXT   ACTION!




     • 今日のお題は所謂�”ビッグデータ”分析


     • ビッグデータかどうかは置いておいて、とにか
       く今あるデータを分散環境で分析してみる!


     • 分散環境で構築しておけばスケールできる!

                                   Developers Summit 2013 Action !   4

Friday, February 15, 13
Developers
         Summit




                 で、アドテクとデータの関係は?




                          Developers Summit 2013 Action !

Friday, February 15, 13
Developers
         Summit

                          アドテクって?




         ”アクション”してもらうためのテクノロジー




                           Developers Summit 2013 Action !   6

Friday, February 15, 13
Developers
         Summit

                          広告を配信する技術



            育児情報サイトの広告

           育児情報サイトだから
           25〜35歳女性向けの広告を出す




                            Developers Summit 2013 Action !   7

Friday, February 15, 13
Developers
         Summit




        でも最近はイクメンもけっこう見てますよ?




                          Developers Summit 2013 Action !

Friday, February 15, 13
Developers
         Summit

              オーディエンスターゲティング



              育児情報 × 男

      出産育児情報サイトを見ている
      男だから保険商品をすすめる



                          Developers Summit 2013 Action !   9

Friday, February 15, 13
Developers
         Summit

              オーディエンスターゲティング



    育児情報サイトを見ている男で保険の切替
    検討中で、株式投資に興味があり、妻から
    旅行に連れて行けとせがまれているけど、
    最近車を買ったからお金が無くて・・・

                          Developers Summit 2013 Action !   10

Friday, February 15, 13
Developers
         Summit

              オーディエンスターゲティング


                データがいっぱいあっても活用しきれない




             自動で似ている人同士をセグメント化したい


                          Developers Summit 2013 Action !   11

Friday, February 15, 13
Developers
         Summit

                          ターゲティングフロー

                                                                          KVS
        userId = XYZ                       site.jp



                                                        userId = XYZ
                クッキーから
                ユーザー識別IDを取得                                            XYZの情報
                KVSからユーザーの
                情報取得




                              Developers Summit 2013 Action !                   12

Friday, February 15, 13
Developers
         Summit

                          ターゲティングフロー

                                                                          KVS
        userId = XYZ                       site.jp



                                                        userId = XYZ
                クッキーから
                ユーザー識別IDを取得                                            XYZの情報
                KVSからユーザーの
                情報取得
                ユーザ情報をベクトル化し                               XYZのベクトル
                てRandomForest


                              Developers Summit 2013 Action !                   13

Friday, February 15, 13
Developers
         Summit

                          ターゲティングフロー

                                                                               KVS
       userId = XYZ                           site.jp
       clusterId = 5


                                                           userId = XYZ
                クッキーから
                ユーザー識別IDを取得                                               XYZの情報
                KVSからユーザーの
                情報取得
                ユーザ情報をベクトル化し                                  XYZのベクトル
                てRandomForest
                clusterIdを取得して
                                                               clusterId = 5
                結果を利用
                                 Developers Summit 2013 Action !                     14

Friday, February 15, 13
Developers
         Summit

                          モデル作成の流れ

                   各ユーザーの情報をKVSに保存

                   各ユーザーの特徴をベクトル化

                   ユーザーベクトルを標準化

                   ユーザーベクトルをmahoutでk-Means

                   k-Meansした結果からRandom Forestモデルを作成

                            Developers Summit 2013 Action !   15

Friday, February 15, 13
Developers
         Summit

                           KVSに保存

                   各ユーザーの情報をKVSに保存

                   各ユーザーの特徴をベクトル化

                   ユーザーベクトルを標準化

                   ユーザーベクトルをmahoutでk-Means

                   k-Meansした結果からRandom Forestモデルを作成

                            Developers Summit 2013 Action !   16

Friday, February 15, 13
Developers
         Summit

                          KVSに保存

         • どのKVSを採用するか?

              ‣

              ‣ 比較してるサイトの情報とかぜんぜんあてにならない

         • データ形式は何にするか?

              ‣ JSON? XML? Avro? MessagePack? protobuf?

                            Developers Summit 2013 Action !   17

Friday, February 15, 13
Developers
         Summit

                           ベクトル化

                   各ユーザーの情報をKVSに保存

                   各ユーザーの特徴をベクトル化

                   ユーザーベクトルを標準化

                   ユーザーベクトルをmahoutでk-Means

                   k-Meansした結果からRandom Forestモデルを作成

                            Developers Summit 2013 Action !   18

Friday, February 15, 13
Developers
         Summit

                                   ベクトル化

           {"ユーザーID":12345,"カテゴリ":{"美容":0,"育児":7,"金融":10,"車":
           4,"マンガ":1,"家具":2,"家電":8,"ペット":0,"グルメ":4},"金額":7600}




          美容         育児       金融   車       マンガ         家具         家電     ペット グルメ   金額

            0             7   10   4           1          2          8   0   4     7600


                                       Developers Summit 2013 Action !                    19

Friday, February 15, 13
Developers
         Summit

                          ベクトルを標準化

                   各ユーザーの情報をKVSに保存

                   各ユーザーの特徴をベクトル化

                   ユーザーベクトルを標準化

                   ユーザーベクトルをmahoutでk-Means

                   k-Meansした結果からRandom Forestモデルを作成

                            Developers Summit 2013 Action !   20

Friday, February 15, 13
Developers
         Summit

                               ベクトルの標準化
          美容         育児       金融       車        マンガ         家具         家電      ペット グルメ 金額
                                                                                お
            0             3     7       5           1          0          6     0   3  8000
            5             6     0       0           0          4          0      0       5     12000
            0             0     1       2           4          3          2      6       3     23000


                              平均0                                         標準偏差1
          美容         育児       金融       車        マンガ         家具         家電      ペット グルメ         金額
         -0.58       0.00     1.14    1.06       -0.32      -1.12      1.09    -0.58   -0.58   -0.82
          1.15       1.00     -0.70   -0.93      -0.80      0.80       -0.87   -0.58   1.15    -0.30
         -0.58       -1.00    -0.44   -0.13      1.12       0.32       -0.22   1.15    -0.58   1.12

                                            Developers Summit 2013 Action !                            21

Friday, February 15, 13
Developers
         Summit

                           Pigを使う

           面倒なMapReduceのJavaプログラムやHadoopコマンド
           を使わずに、Hadoopを操ることができるツール
           (最初はYahooが作った)


           ダウンロードして設定ファイルを編集するだけで使うことが
           できます
            http://pig.apache.org/releases.html#Download
                                          (Hadoop環境があることが前提です)


                           Developers Summit 2013 Action !       22

Friday, February 15, 13
Developers
         Summit

                          PigのUDFを使う



           UDFを作成することでいろいろできます

      % git clone https://github.com/gh-gsd/pigudf.git

      % ant jar.build



                            Developers Summit 2013 Action !   23

Friday, February 15, 13
Developers
         Summit

                          Pigで分散を計算


                register path/to/udfs.jar
                set job.priority very_low;
                set job.name 'CalcVariance';
                define VAR com.gsd.pig.udf.Variance();
                A = load 'mydata' as (data:double);
                B = group A all;
                C = foreach B generate VAR(A.data);
                store C into 'path/to/hdfs/rawdata';


                            Developers Summit 2013 Action !   24

Friday, February 15, 13
Developers
         Summit

                          Mahoutでk-Means

                   各ユーザーの情報をKVSに保存

                   各ユーザーの特徴をベクトル化

                   ユーザーベクトルを標準化

                   ユーザーベクトルをmahoutでk-Means

                   k-Meansした結果からRandom Forestモデルを作成

                             Developers Summit 2013 Action !   25

Friday, February 15, 13
Developers
         Summit




          主にHadoopを用いてデータマイニングや機械学習をするた
          めのJavaライブラリ



            % git clone https://github.com/apache/mahout.git

            % git checkout mahout-0.7

            % mvn install -DskipTests




                              Developers Summit 2013 Action !   26

Friday, February 15, 13
Developers
         Summit

                          k-Means




                          Developers Summit 2013 Action !   27

Friday, February 15, 13
Developers
         Summit

              Mahout k-Meansのデータ型


                           key        : Text
            Input :
                           Value : VectorWritable



                           key        : IntWritable
        Output :
                           Value : WeightedVectorWritable



                                 Developers Summit 2013 Action !   28

Friday, February 15, 13
Developers
         Summit

                              データを変換

                           ユーザーベクトルをスペース区切り
                             に整形したテキストファイル



                            key       : Text
                            Value : VectorWritable

      % $MAHOUT_HOME/bin/mahout 
           org.apache.mahout.clustering.conversion.InputDriver 
               -i path/to/hdfs/rawData 
               -o path/to/hdfs/vectorData

                                  Developers Summit 2013 Action !   29

Friday, February 15, 13
Developers
         Summit

                          k-Meansコマンド
  % MAHOUT_HOME/bin/mahout kmeans 
          -i path/to/hdfs/vectorData                    #入力パス
          -c path/to/hdfs/initialClusters  #初期ノードランダムの場合はどこでも
          -o path/to/hdfs/kmeansResults                 #結果出力パス
          -k 10                                         #クラスタ数
          -dm org.apache.mahout.common.distance.CosineDistanceMeasure 
                                                       #距離計算手法
          -x 20                                         #最大イテレーション回数
          -xm mapreduce                                 #初期ランダムの場合は適当


       結果は  path/to/hdfs/kmeansResults/clusteredPoints                   に出力

                             Developers Summit 2013 Action !               30

Friday, February 15, 13
Developers
         Summit

                                 k-Means 結果
       (map例)
       public void map(IntWritable key, WeightedVectorWritable value,
        OutputCollector<NullWritable, Text> output, Reporter reporter) {
                    try {
                        StringBuilder sb = new StringBuilder();
                        sb.append(key.toString());

                          Iterator<Element> ite = value.getVector().iterator();

                          while (ite.hasNext()) {
                          sb.append(COMMA + ite.next().get());
                          }

                          output.collect(NullWritable.get(),
                                                         new Text(sb.toString()));

                    } catch (InvalidDatastoreException e) {
                        throw new IOException(e);
                    }
       }
                                      Developers Summit 2013 Action !             31

Friday, February 15, 13
Developers
         Summit

                          k-Means 結果

        クラスタID                   ベクトルの値

                      1,0,3,5,7,1,0,9,8,0,1
                      5,6,0,0,0,2,0,0,0,0,2
                      2,0,8,2,0,0,0,0,0,0,0
                      1,0,4,2,3,0,0,6,7,0,4
                      4,0,1,1,1,1,1,1,2,0,0
                      3,5,2,0,1,3,0,9,8,0,1
                      ・・・
                            Developers Summit 2013 Action !   32

Friday, February 15, 13
Developers
         Summit

                          ターゲティングフロー

                                                                               KVS
       userId = XYZ                           site.jp
       clusterId = 5


                                                           userId = XYZ
                クッキーから
                ユーザー識別IDを取得                                               XYZの情報
                KVSからユーザーの
                情報取得
                ユーザ情報をベクトル化し                                  XYZのベクトル
                てRandomForest
                clusterIdを取得して
                                                               clusterId = 5
                結果を利用
                                 Developers Summit 2013 Action !                     33

Friday, February 15, 13
Developers
         Summit

                  MahoutでRandom Forest

                   各ユーザーの情報をKVSに保存

                   各ユーザーの特徴をベクトル化

                   ユーザーベクトルを標準化

                   ユーザーベクトルをmahoutでk-Means

                   k-Meansした結果からRandom Forestモデルを作成

                            Developers Summit 2013 Action !   34

Friday, February 15, 13
Developers
         Summit

                             決定木




                          Developers Summit 2013 Action !   35

Friday, February 15, 13
Developers
         Summit

                          Random Forest




                c-2                                            c-5
                               c-2


                             Developers Summit 2013 Action !     36

Friday, February 15, 13
Developers
         Summit

                  MahoutでRandom Forest

  % mahout org.apache.mahout.classifier.df.tools.Describe 
            -p      path/to/cluster_id_to_vector_text_file             #入力ファイル
            -f      path/to/dataset.info                            #データセット出力先
            -d      L 10 N                                           #データフォーマット


  % mahout org.apache.mahout.classifier.df.mapreduce.BuildForest 
            -d      path/to/cluster_id_to_vector_text_file  #入力ファイル
            -ds path/to/dataset.info                               #データセットファイル
            -o      path/to/decision_forest                            #モデル出力先
            -t      10                                                #作成する木の数


                                  Developers Summit 2013 Action !            37

Friday, February 15, 13
Developers
         Summit

                            モデルのテスト


  % mahout org.apache.mahout.classifier.df.mapreduce.TestForest 
           -i      path/to/test/data                                    #入力テストデータ
           -ds path/to/dataset.info                                   #データセットファイル
           -m      path/to/decision_forest/nsl-forest                     #モデルのパス
           -a                                                            #テスト結果表示
           -mr                                                         #mapreduceを利用
           -o      path/to/output/                                      #テスト結果出力先




                                     Developers Summit 2013 Action !              38

Friday, February 15, 13
Developers
         Summit

                               テスト結果

   12/10/13 18:08:56 INFO mapreduce.TestForest: Classification Time: 0h 0m 6s 355
   12/10/13 18:08:56 INFO mapreduce.TestForest: ==================================
   Summary
   -------------------------------------------------------
   Correctly Classified Instances          :      17657       78.3224%
   Incorrectly Classified Instances        :       4887       21.6776%
   Total Classified Instances              :      22544

   =======================================================
   Confusion Matrix
   -------------------------------------------------------
   a        b       <--Classified as
   9459     252      | 9711      a     = normal
   4635     8198     | 12833     b     = anomaly
   Default Category: unknown: 2




                                Developers Summit 2013 Action !               39

Friday, February 15, 13
Developers
         Summit

                          ターゲティングフロー

                                                                               KVS
       userId = XYZ                           site.jp
       clusterId = 5


                                                           userId = XYZ
                クッキーから
                ユーザー識別IDを取得                                               XYZの情報
                KVSからユーザーの
                情報取得
                ユーザ情報をベクトル化し                                  XYZのベクトル
                てRandomForest
                clusterIdを取得して
                                                               clusterId = 5
                結果を利用
                                 Developers Summit 2013 Action !                     40

Friday, February 15, 13
Developers
          Summit

                                  Classify
      …

      // decisionForestを取得
      DataInputStream decisionForestBinary = getDecisionForestBinary();
      DecisionForest decisionForest = DecisionForest.read(decisionForestBinary);

      // datasetを取得
      DataInputStream datasetBinary = getDatasetBinary();
      Dataset dataset = Dataset.read(datasetBinary);

      // スケール済ベクトルを取得
      String scaledVector = getScaledVector();


      DataConverter dataConverter = new DataConverter(dataset);
      Instance instance = dataConverter.convert(scaleVectorString);

      // ランダム関数
      Random random = new Random();

      // 結果を得る
      double id = decisionForest.classify(random, instance);
                                  Developers Summit 2013 Action !                  41

Friday, February 15, 13
Developers
         Summit

                          モデル作成の流れ

                   各ユーザーの情報をKVSに保存

                   各ユーザーの特徴をベクトル化

                   ユーザーベクトルを標準化

                   ユーザーベクトルをmahoutでk-Means

                   k-Meansした結果からRandom Forestモデルを作成

                            Developers Summit 2013 Action !   42

Friday, February 15, 13
Developers
         Summit




                          ありがとうございました。
                            オウルデータで働きたい!
                             もっとくわしく聞きたい!
                                 という方は
                             「Ask The Speaker」
                             でお待ちしております。

                               Developers Summit 2013 Action !

Friday, February 15, 13

More Related Content

PDF
Developers Summit 2013【15-B-6】開発者の "資産形成" につながる Action とは?
PDF
Developers Summit 2013【15-B-8】タブレット進化論
PDF
無償でここまで使えるアドビのWeb制作ツール for デブサミ2013
PDF
Devsumi2013 Ruby開発者のみなさん、mrubyで楽しく快適な組み込みアプリ開発を始めませんか?
PDF
Open dataとハッカソンで変わる世界
PDF
人が作るソフトウェア 〜今組織パターンを読む意味〜
PPTX
モバイル&コンシューマ向けのシステム開発ができるPHP&Javaプログラマの皆様へ
PDF
デブサミ2013【15D-3】Azureセッション資料
Developers Summit 2013【15-B-6】開発者の "資産形成" につながる Action とは?
Developers Summit 2013【15-B-8】タブレット進化論
無償でここまで使えるアドビのWeb制作ツール for デブサミ2013
Devsumi2013 Ruby開発者のみなさん、mrubyで楽しく快適な組み込みアプリ開発を始めませんか?
Open dataとハッカソンで変わる世界
人が作るソフトウェア 〜今組織パターンを読む意味〜
モバイル&コンシューマ向けのシステム開発ができるPHP&Javaプログラマの皆様へ
デブサミ2013【15D-3】Azureセッション資料

What's hot (20)

PDF
反復型ソフトウェア開発の勘所
PDF
【15-e-7】Kinectから始まったスタートアップ #devsumi
PDF
【15-B-1】AmazonのDevOpsを支えるAWSクラウド
PDF
Devsumi2013 15-C-1 実践!スマホアプリのマネタイズ!! ~マーケット把握術と iPhone&Androidプログラミングテクニック~
PDF
15 c5 dad
PDF
デブサミ2013 【15-B-2】iOS/Android向け開発をビジュアルに!
PDF
One ASP.NET ~ 今、ASP.NET に何が起こっているのか? ~
PDF
Barcode-punk
PDF
MY JOB WEND TO VIETNUM? DevSumi ver.
PDF
[devsumi2013]【15-D-7】実演!現場の悩みをTOCfEで考え抜く!
PDF
devsumi2012 17-D-1 Kinectで創る10年後のカタチ
PDF
プロトタイピングの潮流とデザイナーへの提言
PDF
Enterpriseでもモバイル開発
PDF
Indigo Studio で作るプロトタイプ
PDF
Developers Summit 2013【14-E-3】Windows 8デザインガイド
PDF
ウェブブラウザの時代は終わるのか 〜スマホアプリとHTML5の未来〜
PDF
Agile Japan 2010 「変化を受け入れるアジャイルなプロジェクトマネジメントと現場 &lt;ツール・環境篇>」
PDF
開発生産性、アプリケーションの価値向上に向けてインフラジスティックスがお手伝いさせていただけること
PDF
【14-E-3】Windows 8デザインガイド ~魅力的なWindowsストアアプリとデスクトップアプリを作るために~
PDF
20130629 KA法ワークショップ@DevLOVE仙台
反復型ソフトウェア開発の勘所
【15-e-7】Kinectから始まったスタートアップ #devsumi
【15-B-1】AmazonのDevOpsを支えるAWSクラウド
Devsumi2013 15-C-1 実践!スマホアプリのマネタイズ!! ~マーケット把握術と iPhone&Androidプログラミングテクニック~
15 c5 dad
デブサミ2013 【15-B-2】iOS/Android向け開発をビジュアルに!
One ASP.NET ~ 今、ASP.NET に何が起こっているのか? ~
Barcode-punk
MY JOB WEND TO VIETNUM? DevSumi ver.
[devsumi2013]【15-D-7】実演!現場の悩みをTOCfEで考え抜く!
devsumi2012 17-D-1 Kinectで創る10年後のカタチ
プロトタイピングの潮流とデザイナーへの提言
Enterpriseでもモバイル開発
Indigo Studio で作るプロトタイプ
Developers Summit 2013【14-E-3】Windows 8デザインガイド
ウェブブラウザの時代は終わるのか 〜スマホアプリとHTML5の未来〜
Agile Japan 2010 「変化を受け入れるアジャイルなプロジェクトマネジメントと現場 &lt;ツール・環境篇>」
開発生産性、アプリケーションの価値向上に向けてインフラジスティックスがお手伝いさせていただけること
【14-E-3】Windows 8デザインガイド ~魅力的なWindowsストアアプリとデスクトップアプリを作るために~
20130629 KA法ワークショップ@DevLOVE仙台
Ad

Similar to Devsumi2013_15-c-7 アドテク・ターゲティング技術 (20)

PDF
ソーシャルコーディング革命後の開発委託の世界〜QA@ITの事例
PDF
Developers Summit 2012 16-E-1
PDF
ビッグデータはバズワードか? (Cloudian Summit 2012)
PDF
データマイニングCROSS 2012 Opening Talk - データマイニングの実サービス・ビジネス適用と展望
PDF
Rで階層ベイズモデル
PDF
Devsumi2013 fumi
PDF
データベースを使おう
PDF
20140708 オンラインゲームソリューション
PDF
避けては通れないビッグデータ周辺の重要課題
PDF
「データサイエンティスト・ブーム」後の企業におけるデータ分析者像を探る
PDF
デブサミ2013【14-E-2】パフォーマンス・チューニングに革命をもたらす最新テクノロジー - トランザクショントレース
PDF
SocialAnalyticsとCQ5がスゴイ
PPTX
20130203北大・ビッグデータとプライバシー
PDF
レコメンデーション(協調フィルタリング)の基礎
PDF
10回開催記念 「データマイニング+WEB ~データマイニング・機械学習活用による継続進化~」ー第10回データマイニング+WEB勉強会@東京ー #Toky...
PDF
tut_pfi_2012
PDF
Devsumi2013 gunta 2_pdf
PDF
Jubatus: 分散協調をキーとした大規模リアルタイム機械学習プラットフォーム
PDF
Rでレポートメール
PDF
オープニングトーク - 創設の思い・目的・進行方針  -データマイニング+WEB勉強会@東京
ソーシャルコーディング革命後の開発委託の世界〜QA@ITの事例
Developers Summit 2012 16-E-1
ビッグデータはバズワードか? (Cloudian Summit 2012)
データマイニングCROSS 2012 Opening Talk - データマイニングの実サービス・ビジネス適用と展望
Rで階層ベイズモデル
Devsumi2013 fumi
データベースを使おう
20140708 オンラインゲームソリューション
避けては通れないビッグデータ周辺の重要課題
「データサイエンティスト・ブーム」後の企業におけるデータ分析者像を探る
デブサミ2013【14-E-2】パフォーマンス・チューニングに革命をもたらす最新テクノロジー - トランザクショントレース
SocialAnalyticsとCQ5がスゴイ
20130203北大・ビッグデータとプライバシー
レコメンデーション(協調フィルタリング)の基礎
10回開催記念 「データマイニング+WEB ~データマイニング・機械学習活用による継続進化~」ー第10回データマイニング+WEB勉強会@東京ー #Toky...
tut_pfi_2012
Devsumi2013 gunta 2_pdf
Jubatus: 分散協調をキーとした大規模リアルタイム機械学習プラットフォーム
Rでレポートメール
オープニングトーク - 創設の思い・目的・進行方針  -データマイニング+WEB勉強会@東京
Ad

Devsumi2013_15-c-7 アドテク・ターゲティング技術

  • 1. Developers Summit アドテク・ターゲティング技術 〜Pig, Mahout, KVS〜 太田祐一 15-C-7 株式会社オウルデータ 代表取締役社長 兼 #devsumiC データマイニングエンジニア Developers Summit 2013 Action ! Friday, February 15, 13
  • 2. Developers Summit 自己紹介 太田祐一(おおたゆういち) • 最近子供が生まれてイクメンに • もともとは証券会社員 • 独立して失敗 • スペイシーズにData mining engineerとして拾ってもらう • DMP事業が独立して新会社設立(オウルデータ)→代表に Developers Summit 2013 Action ! 2 Friday, February 15, 13
  • 3. Developers Summit とにかくデータを集めて触ってみよう! Developers Summit 2013 Action ! Friday, February 15, 13
  • 4. Developers Summit とにかくデータを集めて触ってみよう MY RECOMMEND NEXT ACTION! • 今日のお題は所謂�”ビッグデータ”分析 • ビッグデータかどうかは置いておいて、とにか く今あるデータを分散環境で分析してみる! • 分散環境で構築しておけばスケールできる! Developers Summit 2013 Action ! 4 Friday, February 15, 13
  • 5. Developers Summit で、アドテクとデータの関係は? Developers Summit 2013 Action ! Friday, February 15, 13
  • 6. Developers Summit アドテクって? ”アクション”してもらうためのテクノロジー Developers Summit 2013 Action ! 6 Friday, February 15, 13
  • 7. Developers Summit 広告を配信する技術 育児情報サイトの広告 育児情報サイトだから 25〜35歳女性向けの広告を出す Developers Summit 2013 Action ! 7 Friday, February 15, 13
  • 8. Developers Summit でも最近はイクメンもけっこう見てますよ? Developers Summit 2013 Action ! Friday, February 15, 13
  • 9. Developers Summit オーディエンスターゲティング 育児情報 × 男 出産育児情報サイトを見ている 男だから保険商品をすすめる Developers Summit 2013 Action ! 9 Friday, February 15, 13
  • 10. Developers Summit オーディエンスターゲティング 育児情報サイトを見ている男で保険の切替 検討中で、株式投資に興味があり、妻から 旅行に連れて行けとせがまれているけど、 最近車を買ったからお金が無くて・・・ Developers Summit 2013 Action ! 10 Friday, February 15, 13
  • 11. Developers Summit オーディエンスターゲティング データがいっぱいあっても活用しきれない 自動で似ている人同士をセグメント化したい Developers Summit 2013 Action ! 11 Friday, February 15, 13
  • 12. Developers Summit ターゲティングフロー KVS userId = XYZ site.jp userId = XYZ クッキーから ユーザー識別IDを取得 XYZの情報 KVSからユーザーの 情報取得 Developers Summit 2013 Action ! 12 Friday, February 15, 13
  • 13. Developers Summit ターゲティングフロー KVS userId = XYZ site.jp userId = XYZ クッキーから ユーザー識別IDを取得 XYZの情報 KVSからユーザーの 情報取得 ユーザ情報をベクトル化し XYZのベクトル てRandomForest Developers Summit 2013 Action ! 13 Friday, February 15, 13
  • 14. Developers Summit ターゲティングフロー KVS userId = XYZ site.jp clusterId = 5 userId = XYZ クッキーから ユーザー識別IDを取得 XYZの情報 KVSからユーザーの 情報取得 ユーザ情報をベクトル化し XYZのベクトル てRandomForest clusterIdを取得して clusterId = 5 結果を利用 Developers Summit 2013 Action ! 14 Friday, February 15, 13
  • 15. Developers Summit モデル作成の流れ 各ユーザーの情報をKVSに保存 各ユーザーの特徴をベクトル化 ユーザーベクトルを標準化 ユーザーベクトルをmahoutでk-Means k-Meansした結果からRandom Forestモデルを作成 Developers Summit 2013 Action ! 15 Friday, February 15, 13
  • 16. Developers Summit KVSに保存 各ユーザーの情報をKVSに保存 各ユーザーの特徴をベクトル化 ユーザーベクトルを標準化 ユーザーベクトルをmahoutでk-Means k-Meansした結果からRandom Forestモデルを作成 Developers Summit 2013 Action ! 16 Friday, February 15, 13
  • 17. Developers Summit KVSに保存 • どのKVSを採用するか? ‣ ‣ 比較してるサイトの情報とかぜんぜんあてにならない • データ形式は何にするか? ‣ JSON? XML? Avro? MessagePack? protobuf? Developers Summit 2013 Action ! 17 Friday, February 15, 13
  • 18. Developers Summit ベクトル化 各ユーザーの情報をKVSに保存 各ユーザーの特徴をベクトル化 ユーザーベクトルを標準化 ユーザーベクトルをmahoutでk-Means k-Meansした結果からRandom Forestモデルを作成 Developers Summit 2013 Action ! 18 Friday, February 15, 13
  • 19. Developers Summit ベクトル化 {"ユーザーID":12345,"カテゴリ":{"美容":0,"育児":7,"金融":10,"車": 4,"マンガ":1,"家具":2,"家電":8,"ペット":0,"グルメ":4},"金額":7600} 美容 育児 金融 車 マンガ 家具 家電 ペット グルメ 金額 0 7 10 4 1 2 8 0 4 7600 Developers Summit 2013 Action ! 19 Friday, February 15, 13
  • 20. Developers Summit ベクトルを標準化 各ユーザーの情報をKVSに保存 各ユーザーの特徴をベクトル化 ユーザーベクトルを標準化 ユーザーベクトルをmahoutでk-Means k-Meansした結果からRandom Forestモデルを作成 Developers Summit 2013 Action ! 20 Friday, February 15, 13
  • 21. Developers Summit ベクトルの標準化 美容 育児 金融 車 マンガ 家具 家電 ペット グルメ 金額 お 0 3 7 5 1 0 6 0 3 8000 5 6 0 0 0 4 0 0 5 12000 0 0 1 2 4 3 2 6 3 23000 平均0 標準偏差1 美容 育児 金融 車 マンガ 家具 家電 ペット グルメ 金額 -0.58 0.00 1.14 1.06 -0.32 -1.12 1.09 -0.58 -0.58 -0.82 1.15 1.00 -0.70 -0.93 -0.80 0.80 -0.87 -0.58 1.15 -0.30 -0.58 -1.00 -0.44 -0.13 1.12 0.32 -0.22 1.15 -0.58 1.12 Developers Summit 2013 Action ! 21 Friday, February 15, 13
  • 22. Developers Summit Pigを使う 面倒なMapReduceのJavaプログラムやHadoopコマンド を使わずに、Hadoopを操ることができるツール (最初はYahooが作った) ダウンロードして設定ファイルを編集するだけで使うことが できます http://pig.apache.org/releases.html#Download (Hadoop環境があることが前提です) Developers Summit 2013 Action ! 22 Friday, February 15, 13
  • 23. Developers Summit PigのUDFを使う UDFを作成することでいろいろできます % git clone https://github.com/gh-gsd/pigudf.git % ant jar.build Developers Summit 2013 Action ! 23 Friday, February 15, 13
  • 24. Developers Summit Pigで分散を計算 register path/to/udfs.jar set job.priority very_low; set job.name 'CalcVariance'; define VAR com.gsd.pig.udf.Variance(); A = load 'mydata' as (data:double); B = group A all; C = foreach B generate VAR(A.data); store C into 'path/to/hdfs/rawdata'; Developers Summit 2013 Action ! 24 Friday, February 15, 13
  • 25. Developers Summit Mahoutでk-Means 各ユーザーの情報をKVSに保存 各ユーザーの特徴をベクトル化 ユーザーベクトルを標準化 ユーザーベクトルをmahoutでk-Means k-Meansした結果からRandom Forestモデルを作成 Developers Summit 2013 Action ! 25 Friday, February 15, 13
  • 26. Developers Summit 主にHadoopを用いてデータマイニングや機械学習をするた めのJavaライブラリ % git clone https://github.com/apache/mahout.git % git checkout mahout-0.7 % mvn install -DskipTests Developers Summit 2013 Action ! 26 Friday, February 15, 13
  • 27. Developers Summit k-Means Developers Summit 2013 Action ! 27 Friday, February 15, 13
  • 28. Developers Summit Mahout k-Meansのデータ型  key : Text Input :  Value : VectorWritable  key : IntWritable Output :  Value : WeightedVectorWritable Developers Summit 2013 Action ! 28 Friday, February 15, 13
  • 29. Developers Summit データを変換 ユーザーベクトルをスペース区切り に整形したテキストファイル   key : Text   Value : VectorWritable % $MAHOUT_HOME/bin/mahout org.apache.mahout.clustering.conversion.InputDriver  -i path/to/hdfs/rawData -o path/to/hdfs/vectorData Developers Summit 2013 Action ! 29 Friday, February 15, 13
  • 30. Developers Summit k-Meansコマンド % MAHOUT_HOME/bin/mahout kmeans  -i path/to/hdfs/vectorData  #入力パス -c path/to/hdfs/initialClusters  #初期ノードランダムの場合はどこでも -o path/to/hdfs/kmeansResults  #結果出力パス -k 10  #クラスタ数 -dm org.apache.mahout.common.distance.CosineDistanceMeasure   #距離計算手法 -x 20  #最大イテレーション回数 -xm mapreduce  #初期ランダムの場合は適当 結果は  path/to/hdfs/kmeansResults/clusteredPoints に出力 Developers Summit 2013 Action ! 30 Friday, February 15, 13
  • 31. Developers Summit k-Means 結果 (map例) public void map(IntWritable key, WeightedVectorWritable value,  OutputCollector<NullWritable, Text> output, Reporter reporter) { try { StringBuilder sb = new StringBuilder(); sb.append(key.toString()); Iterator<Element> ite = value.getVector().iterator(); while (ite.hasNext()) { sb.append(COMMA + ite.next().get()); } output.collect(NullWritable.get(), new Text(sb.toString())); } catch (InvalidDatastoreException e) { throw new IOException(e); } } Developers Summit 2013 Action ! 31 Friday, February 15, 13
  • 32. Developers Summit k-Means 結果 クラスタID ベクトルの値 1,0,3,5,7,1,0,9,8,0,1 5,6,0,0,0,2,0,0,0,0,2 2,0,8,2,0,0,0,0,0,0,0 1,0,4,2,3,0,0,6,7,0,4 4,0,1,1,1,1,1,1,2,0,0 3,5,2,0,1,3,0,9,8,0,1 ・・・ Developers Summit 2013 Action ! 32 Friday, February 15, 13
  • 33. Developers Summit ターゲティングフロー KVS userId = XYZ site.jp clusterId = 5 userId = XYZ クッキーから ユーザー識別IDを取得 XYZの情報 KVSからユーザーの 情報取得 ユーザ情報をベクトル化し XYZのベクトル てRandomForest clusterIdを取得して clusterId = 5 結果を利用 Developers Summit 2013 Action ! 33 Friday, February 15, 13
  • 34. Developers Summit MahoutでRandom Forest 各ユーザーの情報をKVSに保存 各ユーザーの特徴をベクトル化 ユーザーベクトルを標準化 ユーザーベクトルをmahoutでk-Means k-Meansした結果からRandom Forestモデルを作成 Developers Summit 2013 Action ! 34 Friday, February 15, 13
  • 35. Developers Summit 決定木 Developers Summit 2013 Action ! 35 Friday, February 15, 13
  • 36. Developers Summit Random Forest c-2 c-5 c-2 Developers Summit 2013 Action ! 36 Friday, February 15, 13
  • 37. Developers Summit MahoutでRandom Forest % mahout org.apache.mahout.classifier.df.tools.Describe  -p path/to/cluster_id_to_vector_text_file #入力ファイル -f path/to/dataset.info #データセット出力先 -d L 10 N #データフォーマット % mahout org.apache.mahout.classifier.df.mapreduce.BuildForest  -d path/to/cluster_id_to_vector_text_file  #入力ファイル -ds path/to/dataset.info #データセットファイル -o path/to/decision_forest  #モデル出力先 -t 10   #作成する木の数 Developers Summit 2013 Action ! 37 Friday, February 15, 13
  • 38. Developers Summit モデルのテスト % mahout org.apache.mahout.classifier.df.mapreduce.TestForest  -i path/to/test/data  #入力テストデータ -ds path/to/dataset.info #データセットファイル -m path/to/decision_forest/nsl-forest #モデルのパス -a #テスト結果表示 -mr #mapreduceを利用 -o path/to/output/ #テスト結果出力先 Developers Summit 2013 Action ! 38 Friday, February 15, 13
  • 39. Developers Summit テスト結果 12/10/13 18:08:56 INFO mapreduce.TestForest: Classification Time: 0h 0m 6s 355 12/10/13 18:08:56 INFO mapreduce.TestForest: ================================== Summary ------------------------------------------------------- Correctly Classified Instances : 17657 78.3224% Incorrectly Classified Instances : 4887 21.6776% Total Classified Instances : 22544 ======================================================= Confusion Matrix ------------------------------------------------------- a b <--Classified as 9459 252 | 9711 a = normal 4635 8198 | 12833 b = anomaly Default Category: unknown: 2 Developers Summit 2013 Action ! 39 Friday, February 15, 13
  • 40. Developers Summit ターゲティングフロー KVS userId = XYZ site.jp clusterId = 5 userId = XYZ クッキーから ユーザー識別IDを取得 XYZの情報 KVSからユーザーの 情報取得 ユーザ情報をベクトル化し XYZのベクトル てRandomForest clusterIdを取得して clusterId = 5 結果を利用 Developers Summit 2013 Action ! 40 Friday, February 15, 13
  • 41. Developers Summit Classify … // decisionForestを取得 DataInputStream decisionForestBinary = getDecisionForestBinary(); DecisionForest decisionForest = DecisionForest.read(decisionForestBinary); // datasetを取得 DataInputStream datasetBinary = getDatasetBinary(); Dataset dataset = Dataset.read(datasetBinary); // スケール済ベクトルを取得 String scaledVector = getScaledVector(); DataConverter dataConverter = new DataConverter(dataset); Instance instance = dataConverter.convert(scaleVectorString); // ランダム関数 Random random = new Random(); // 結果を得る double id = decisionForest.classify(random, instance); Developers Summit 2013 Action ! 41 Friday, February 15, 13
  • 42. Developers Summit モデル作成の流れ 各ユーザーの情報をKVSに保存 各ユーザーの特徴をベクトル化 ユーザーベクトルを標準化 ユーザーベクトルをmahoutでk-Means k-Meansした結果からRandom Forestモデルを作成 Developers Summit 2013 Action ! 42 Friday, February 15, 13
  • 43. Developers Summit ありがとうございました。 オウルデータで働きたい! もっとくわしく聞きたい! という方は 「Ask The Speaker」 でお待ちしております。 Developers Summit 2013 Action ! Friday, February 15, 13