08.10.2016 Views

Foundations of Data Science

2dLYwbK

2dLYwbK

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Thus<br />

∂J<br />

∂w j<br />

= ∑ i<br />

(<br />

σ(w T x)(1 − σ(w T x))<br />

l i x<br />

σ(w T j − (1 − l i ) (1 − )<br />

σ(wT x))σ(w T x)<br />

x<br />

x)<br />

1 − σ(w T j<br />

x)<br />

)<br />

(l i (1 − σ(w T x))x j − (1 − l i )σ(w T x)x j<br />

= ∑ i<br />

((l i x j − l i σ(w T x)x j − σ(w T x)x j + l i σ(w T x)x j<br />

)<br />

= ∑ i<br />

= ∑ i<br />

(<br />

)<br />

l i − σ(w T x) x j .<br />

S<strong>of</strong>tmax is a generalization <strong>of</strong> logistic regression to multiple classes. Thus, the labels<br />

l i take on values {1, 2, . . . , k}. For an input x, s<strong>of</strong>tmax estimates the probability <strong>of</strong> each<br />

label. The hypothesis is <strong>of</strong> the form<br />

⎡<br />

h w (x) = ⎢<br />

⎣<br />

Prob(l = 1|x, w 1 )<br />

Prob(l = 2|x, w 2 )<br />

.<br />

Prob(l = k|x, w k )<br />

where the matrix formed by the weight vectors is<br />

⎡ ⎤<br />

w 1<br />

w 2<br />

W = ⎢ ⎥<br />

⎣ . ⎦<br />

w k<br />

⎤<br />

⎡<br />

⎥<br />

⎦ = 1<br />

∑ k<br />

⎢<br />

i=1 ewT i x ⎣<br />

W is a matrix since for each label l i , there is a vector w i <strong>of</strong> weights.<br />

and<br />

Consider a set <strong>of</strong> n inputs {x 1 , x 2 , . . . , x n }. Define<br />

{ 1 if l = k<br />

δ(l = k) =<br />

0 otherwise<br />

J(W ) =<br />

n∑<br />

i=1<br />

k∑<br />

e wT j x i<br />

δ(l i = j) log ∑ k<br />

h=1 ewT h x i<br />

The derivative <strong>of</strong> the cost function with respect to the weights is<br />

∇ wi J(W ) = −<br />

j=1<br />

⎤<br />

e wT 1 x<br />

e wT 2 x<br />

⎥<br />

. ⎦<br />

e wT k x<br />

n∑ (<br />

x j δ(lj = k) − Prob(l j = k)|x j , W )<br />

j=1<br />

226

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!