티스토리 뷰

"해당 포스팅은 Coursera 에서 수강한 Andew Ng 의 deep learning specialization 코스를 요약한 것입니다." 


Dot product : 내가 아는 행렬 곱.

x1, x2 2개의 features 가 있다고 할 때, hidden unit  이 하나 있다고 해 봐 

x1*w1 + x2*w2 + b => 즉 x1*w1 + x2*w2 이 dot product 라서 곱할 때 dot product 를 구하는 거임. 

 

반면 np.multiply 는 element wise 곱이기 때문에 두 행렬의 shape 이 같아야지만 곱할 수 있음. 같지 않아도 되는 경우는 numpy 가 broad casting 으로 임의로 2개의 shape 을 같도록 만들어서 가능한 거임. 

 

np.dot

|A B| . |E F| = |A*E+B*G A*F+B*H|
|C D|   |G H|   |C*E+D*G C*F+D*H|

np.multiply (element-wise)

|A B| ⊙ |E F| = |A*E B*F|
|C D|   |G H|   |C*G D*H|
출처: stackoverflow.com/a/48201957

2. Decision boundry 그리기 

Decision boundry  를 어떻게 그리냐하면, 우선 데이터 포인트는 주어져 있으니까 그대로 scatter 하면 되는 거지만 decision boundary (countour line) 은 어떻게 그리냐? grid 를 그려놓고, 이 gid 의 모든 point 에 대해서 predict 하면 그게 contour 가 되는 거임 (!!). 

 

Decision boundary. (Y = blue, red) 

def plot_decision_boundary(model, X, y):
    # Set min and max values and give it some padding
    x_min, x_max = X[0, :].min() - 1, X[0, :].max() + 1
    y_min, y_max = X[1, :].min() - 1, X[1, :].max() + 1
    h = 0.01
    # Generate a grid of points with distance h between them
    xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
    # Predict the function value for the whole grid
    Z = model(np.c_[xx.ravel(), yy.ravel()])
    Z = Z.reshape(xx.shape)
    # Plot the contour and training examples
    plt.contourf(xx, yy, Z, cmap=plt.cm.Spectral)
    plt.ylabel('x2')
    plt.xlabel('x1')
    plt.scatter(X[0, :], X[1, :], c=y, cmap=plt.cm.Spectral)

코드 출처: https://github.com/rvarun7777/Deep_Learning/blob/master/Neural%20Networks%20and%20Deep%20Learning/Week%203/Planar%20data%20classification%20with%20one%20hidden%20layer/planar_utils.py

 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함