4. Part I
エンタープライズでの機械学習技術利用の広がり
ビッグデータ処理と統計学的アプローチ
機械学習技術とは何か?
2014年の各社の動き
Google Prediction API
MS Azure Machine Learning
IBM Watson Analytics
機械学習への期待の背景
小売業の変化
30. Microsoft Azure
Machine Learning
2014年6月16日
“Microsoft Azure Machine Learning
combines power of comprehensive machine
learning with benefits of cloud”
http://bit.ly/1zlFNFm
56. “The Future of Shopping”
-- RichRelevance社White Paper
マーケティングと小売業は、ますます強く、解けない計算
のように感じられるかもしれない。新しいトレンド、アプ
ローチ、デジタル・チャンネルは、毎朝、次々生えてくる
マッシュルームのように見える。ブランドでも小売でも、両
方で、誰もが、何が妥当なのか、この次に出てくる新しい
ものは何なのかに頭を悩ませている。LinkedIn,
Facebook, YouTube, Twitter, Google+ ... これら
の新しいチャンネルのそれぞれが、ある決定を必要として
いる。それをするかしないかの。もし、それをするとすれば、
既存のメッセージや製品やキャンペーンのコンテンツをカ
スタマイズしたり目標の再設定をすべきなのか? そして、
それに慣れた頃、InstagramやPinterestが現れる。ど
こで、それは終わるのだろうか?
57. “The Future of Shopping”
-- RichRelevance社White Paper
それは終わりはしない。しかし、ひとたび、個別の要素を
定義し解決すれば、そんなに複雑なことにはならない。
未来のショッピングの基礎は、少数の議論の余地のない
事実の中にある。ソーシャル・メディアは存在を続け、あな
たの顧客は決定的にMobileで、ますますローカルなもの
になる。そして女性が重要な鍵を握っている。
127. Boosted Decision Tree
Fermi Lab
http://www-boone.fnal.gov/slides-talks/
conf-talk/yang/boosting-ccast.ppt
128. The MiniBooNE Detector
• 12m diameter tank
• Filled with 800 tons
of ultra pure mineral oil
• Optically isolated inner
region with 1280 PMTs
• Outer veto region with 240
PMTs.
11.6-10,2006 H.J.Yang - CCAST Workshop 128
130. ANN vs BDT-Performance/Stability
30 variables for training
10 Training Samples(30k/30k):
selected randomly from 50000 signal
and 80000 background events.
Testing Sample:
54291 signal and 166630 background
Smearing Testing Sample:
Each Variable and testing event is
smeared randomly using the formula,
V_ij = V_ij * ( 1 + smear*Rand_ij )
Where Rand_ij is random number with
normal Gaussian distribution.
11.6-10,2006 H.J.Yang - CCAST Workshop 130
132. Support Vector Machine
Christopher Manning and Pandu Nayak
CS 276 :Information Retrieval and Web Search
http://web.stanford.edu/class/cs276/
133. History
The Study on Statistical
Learning Theory was started
in the 1960s by Vapnik
Statistical Learning Theory is
the theory about Machine
Learning Principle from a
small sample size.
Support Vector Machine is a
practical learning method
based on Statistical Learning
Theory
A simple SVM could beat a
sophisticated neural
networks with elaborate
features in a handwriting
recognition task.
134. 線形のClassifiers
denotes +1
denotes -1
f(x,w,b) = sign(w x + b)
このデータをどの
ように分類する
か?
w x + b<0
w x + b>0
135. denotes +1
denotes -1
f(x,w,b) = sign(w x + b)
線形のClassifiers
このデータをどの
ように分類する
か?
136. denotes +1
denotes -1
f(x,w,b) = sign(w x + b)
線形のClassifiers
このデータをどの
ように分類する
か?
137. denotes +1
denotes -1
f(x,w,b) = sign(w x + b)
このどれでもいい
のだが、...
どれが一番いいの
だろう?
線形のClassifiers
138. denotes +1
denotes -1
f(x,w,b) = sign(w x + b)
+1クラスへの
誤った分類
線形のClassifiers
このデータをどの
ように分類する
か?
139. denotes +1
denotes -1
f(x,w,b) = sign(w x + b)
線形のClassifier
のマージンを、そ
の境界がデータ
の点にぶつかるま
で増やすことので
きる幅として定義す
る
.
線形のClassifiers
140. denotes +1
denotes -1
f(x,w,b) = sign(w x + b)
最大マージン
Classifierは、
最大のマージンを
持つClassifierに
他ならない。
これが一番単純な
SVM(LSVM)と呼ば
れるものだ。
Linear SVM
Support Vectors
は、マージンが
迫っているデータ
点である。
1. マージンを最大にすることは、直感的に
もPAC理論的にも正しい。
2. このことは、Support Vectorだけが重要
であることを意味する。それ以外の訓練
用データは、無視できる。
3. 経験的には、これはとてもうまく働く。
最大のマージン
141. Sec. 15.1
141
マージンの幾何
超平面に最も近いデータの点がSupport Vector。
マージンρ は、クラスのSupport Vector の間の分離幅
x ρ
r
x′
w
r: の計算
点線x’−x は、決定境界と垂直だから
wとは平行である。その単位ベクトルは
w/|w|, だからこの直線は、rw/|w|。
x’ = x – yrw/|w|で、
x‘ はwTx’+b = 0を満たすので、
wT(x –yrw/|w|) + b = 0
|w| = sqrt(wTw) を使えば、
wTx –yr|w| + b = 0
これをrについて解けば、r が求まる。
r = y(wTx + b)/|w|
142. 142
数学的に見たLinear SVM
線形分離が可能な場合
全てのデータが、超平面から少なくとも距離1だけ離れていると仮定しよ
う。この時、次の二つの条件式が訓練用データ{(xi ,yi)} について成り立つ。
wTxi + b ≥ 1 if yi = 1
wTxi + b ≤ −1 if yi = −1
Support vectorにとっては、不等号は等号になる。
先に見たように、超平面からの全てのサンプルの距離は、次の式であら
わされるので、
w x b
マージンの値は、次のようになる
2
w
r =
w
r y
T +
=
Sec. 15.1
143. wTxa + b = 1
143
Linear Support Vector Machine (SVM)
仮説
wT x + b = 0
そのほかのスケールからの条件
mini=1,…,n |wTxi + b| = 1
これから、次の式が導かれる
wT(xa–xb) = 2
ρ = ||xa–xb||2 = 2/||w||2
wT x + b = 0
wTxb + b = -1
ρ
Sec. 15.1
144. が最大となり、かつ全ての{(xi , yi)}で、
144
Linear SVMs Mathematically (cont.)
こうして、二次の最適化問題を定式化できる
次の条件を満たすw とb をみつけよ。
2
w
= r
wTxi + b ≥ 1 if yi=1; wTxi + b ≤ -1 if yi = -1
より良い定式化は(min ||w|| = max 1/ ||w|| なので):
次の条件を満たすw とb をみつけよ。
Φ(w) =½ wTw は、最小となり;
全ての{(xi ,yi)}について、yi (wTxi + b) ≥ 1
Sec. 15.1
148. Soft Margin Classification
分離が難しく、あるいは、ノイズが多いデータには、誤分
類を許すように、ゆるい(slack)変数ξi を追加するこ
とができる。
e11
e7
e2
二次の最適化の基準はどう
なるか?
次の式を最小化する
R
C εk
k
1
1
w .
w
2
149. Hard Margin v.s. Soft Margin
古い定式化
Find w and b such that
Φ(w) =½ wTw is minimized and for all {(xi ,yi)}
yi (wTxi + b) ≥ 1
Slack変数込みの新しい定式化
Find w and b such that
Φ(w) =½ wTw + CΣξi is minimized and for all
{(xi ,yi)}
yi (wTxi + b) ≥ 1- ξi and ξi ≥ 0 for all i
パラメータC は、オーバー・フィッティングをコントロールする
ものと考えればいい。
150. Linear SVMs: まとめ
分類子は、分離超平面である。
もっとも重要な訓練用データは、Support Vectorである。それは、超
平面を定義する。
二次最適化アルゴリズムは、どの訓練用データがSupport Vectorで
あるかを、非ゼロのラグランジェ未定乗数αi で決めることができる。
問題のデュアルな定式化でも、この解でも、両方で、訓練用データはドッ
ト積の内部にしか現れない。
Find α1…αN such that
Q(α) =Σαi - ½ΣΣαiαjyiyjxi
Txj is maximized and
(1) Σαiyi = 0
(2) 0 ≤ αi ≤ C for all αi
Tx + b
f(x) = Σαiyixi
155. Kernel Functions の例
線形: K(xi,xj)= xi
Txj
p乗の多項式: K(xi,xj)= (1+ xi
Txj)p
Gaussian (radial-basis function network):
i j
( , ) exp( 2
Sigmoid: K(xi,xj)= tanh(β0xi
)
Txj + β1)
2
2
i j
x x
x x
K
177. Attribute 1: (qualitative)
Status of existing checking
account
Attribute 2: (numerical)
Duration in month
Attribute 3: (qualitative)
Credit history
Attribute 4: (qualitative)
Purpose
Attribute 5: (numerical)
Credit amount
Attibute 6: (qualitative)
Savings account/bonds
Attribute 7: (qualitative)
Present employment since
Attribute 8: (numerical)
Installment rate in
percentage of disposable
income
Attribute 9: (qualitative)
Personal status and sex
Attribute 10: (qualitative)
Other debtors / guarantors
Attribute 11: (numerical)
Present residence since
Attribute 12: (qualitative)
Property
Attribute 13: (numerical)
Age in years
Attribute 14: (qualitative)
Other installment plans
Attribute 15: (qualitative)
Housing
Attribute 16: (numerical)
Number of existing credits
at this bank
Attribute 17: (qualitative)
Job
Attribute 18: (numerical)
Number of people being
liable to provide
maintenance for
Attribute 19: (qualitative)
Telephone
Attribute 20: (qualitative)
foreign worker
188. Metadata Editor
New Column Field
1. Status of checking
account
2. Duration in months
3. Credit history
4. Purpose
5. Credit amount
6. Savings account/bond
7. Present employment
since
8. Installment rate in
percentage of disposable
income
9. Personal status and sex
10. Other
debtors/guarantors
11. Present residence since
12. Property
13. Age in years
14. Other installment plans
15. Housing
16. Number of existing
credits at this bank
17. Job
18. Number of people being
liable to provide
maintenance for
19. Telephone
20. Foreign worker
21.Credit risk
192. R Script モジュールの実行
dataset1 <- maml.mapInputPort(1)
data.set<-dataset1[dataset1[,21]==1,]
pos<-dataset1[dataset1[,21]==2,]
for (i in 1:5) data.set<-rbind(data.set,pos)
maml.mapOutputPort("data.set")
225. 訓練用の実験からスコア用の実験に変更する
boosted tree modelが、良い成績を収めたので、それ
を利用することを決めたので、最初に行うことは、SVCの
訓練用モデルを削除することである。
Two-Class Support Vector Machineを削除
それに接続していた、Train Model とScore Modelを
削除
Transform Data By Scalingモジュールを削除
226. 訓練用の実験からスコア用の実験に変更する
訓練したboosted tree model を保存する。それから、訓
練のために使った残りのモジュールを削除し、訓練されたモ
デルに置き換えることができる。
残ったTrain Modelモジュールを右クリックで開き、Save
as Trained Modelを選択する。Trained Modelの名前を
入力する。例えば、“Credit Risk Prediction”にする。
いったん、Trained Modelが保存されると、それはモ
ジュール・パレットに現れ、別の実験で使うことができる。
Two-Class Boosted Decision Tree とTrain Model
モジュールを削除する。
Credit Risk Prediction モデルをScore Modelモジュー
ルの左側の入力に接続する。
246. library("RCurl")
library("RJSONIO")
h = basicTextGatherer()
req = list(Id="score00001",
Instance=list(FeatureVector=list(
"row.names"= "0",
"Status of checking account"= "0",
"Duration in months"= "0",
"Credit history"= "0",
"Purpose"= "0",
"Credit amount"= "0",
"Savings account/bond"= "0",
"Present employment since"= "0",
"Installment rate in percentage of disposable income"= "0",
"Personal status and sex"= "0",
"Other debtors"= "0",
"Present residence since"= "0",
"Property"= "0",
"Age in years"= "0",
"Other installment plans"= "0",
"Housing"= "0",
247. "Number of existing credits"= "0",
"Job"= "0",
"Number of people providing maintenance for"= "0",
"Telephone"= "0",
"Foreign worker"= "0",
"Credit risk"= "0"
),GlobalParameters=fromJSON('{}')))
body = toJSON(req)
api_key = "abc123"
# You can obtain the API key from the publisher of the web service
h$reset()
curlPerform(
url = "http://xxx.cloudapp.net/workspaces/xxx/services/xxx/score",
httpheader=c('Content-Type' = "application/json",
'Authorization' = "Bearer " + api_key),
postfields=body,
writefunction = h$update,
verbose = TRUE
)
result = h$value()
252. モデル
2011年のデータを訓練用データとして使い、2012年の
データをテスト用データとして使用する。
次の四つの特徴のセットを比較する。
A. 予想される日の、天候+ 休日・平日・週末という特徴
B. 直前の12時間に貸し出された自転車の数
C. 同じ時間帯で、直前の12日間で貸し出された自転車の数
D. 同じ時間帯・同じ日の条件で、以前の12週間で貸し出さ
れた自転車の数