νŒŒμ΄ν† μΉ˜

λͺ¨λ‘μ˜ λ”₯λŸ¬λ‹ -νŒŒμ΄ν† μΉ˜ ch1-ch2 정리

JihyunLee 2019. 3. 19. 23:07
λ°˜μ‘ν˜•

λͺ¨λ‘μ˜ λ”₯λŸ¬λ‹ 링크 : https://www.youtube.com/watch?v=SKq-pmkekTk&list=PLbbloOsdWVwTNNkjnLuqEWtzjRqfBALF7


λͺ¨λ‘μ˜ λ”₯λŸ¬λ‹ ch1


μ‚¬λžŒμ΄ 결정을 ν•˜λŠ” 방식

data-> human -> infer or predict


μ»΄ν“¨ν„°μ˜ 방식 ν•˜λŠ”κ²ƒ machine learning

data -> computer -> infer or predict

λͺ¨λ‘μ˜ λ”₯λŸ¬λ‹ ch2

'μ•„λž˜ λ°μ΄ν„°λŠ” x μ‹œκ°„ κ³΅λΆ€ν–ˆμ„λ•Œ point λ₯Ό y만큼 λ°›λŠ”λ‹€' 데이터이닀.


supervised learning 은 x-y 처럼 정닡이 μžˆλŠ” 데이터셋 ν•™μŠ΅μ„ λ§ν•œλ‹€.


κ°€μž₯ 기본적인 식 


y헷은 좔정값을 μ˜λ―Έν•œλ‹€.


WλŠ” κ°€μ€‘μΉ˜λ‘œ,  λžœλ€μœΌλ‘œ μ‹œμž‘ν•˜μ—¬, μ‹€μ œκ°’-μΆ”μ •κ°’μ˜ 크기λ₯Ό μ€„μ΄λŠ” λ°©ν–₯으둜 μ§„ν–‰ν•΄μ•Ό ν•œλ‹€.

μ‹€μ œκ°’-μΆ”μ •κ°’μ˜ 차이λ₯Ό μ—¬λŸ¬κ°€μ§€ κ°’μœΌλ‘œ λ‚˜νƒ€λ‚Όμˆ˜ μžˆλ‹€(loss ν•¨μˆ˜μ˜ μ’…λ₯˜κ°€ μ—¬λŸ¬κ°€μ§€μ΄λ‹€.)


λ¨Έμ‹ λŸ¬λ‹μ˜ goal은 μ˜€μ°¨κ°€ κ°€μž₯μž‘μ€ wλ₯Ό κ΅¬ν•˜λŠ”κ²ƒ

μ£Όμ–΄μ§„ λ°μ΄ν„°μ…‹μ˜ μ˜€μ°¨λ₯Ό ν‰κ· μ„ κ΅¬ν•΄μ„œ, μ§€κΈˆ μ–Όλ§ŒνΌ μ‹€μ œκ°’κ³Ό λ–¨μ–΄μ Έ μžˆλŠ”μ§€λ₯Ό κ΅¬ν•œλ‹€.


μ•„λž˜λŠ” κ°€μ€‘μΉ˜μ™€ 였차의 의미λ₯Ό 잘 λ³΄μ—¬μ£ΌλŠ” μ˜ˆμ‹œμ½”λ“œμ΄λ‹€.


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
32
33
34
35
36
import numpy as np
import matplotlib.pyplot as plt
 
x_data = [1.0,2.0,3.0]
y_data = [2.0,4.0,6.0]
 
w=1.0
 
def forward(x):
    return x*w
 
def loss(x,y):
    y_pred = forward(x)
    return (y_pred-y) * (y_pred-y)
 
w_list =[]
mse_list =[]
 
for w in np.arange(0.0,4.1,0.1):#0.0λΆ€ν„° 4.1κΉŒμ§€ 0.1 κ°„κ²©μœΌλ‘œ w μ¦κ°€
    print ("w=",w)
    l_sum =0
    for x_val, y_val in zip(x_data, y_data):
        y_pred_val = forward(x_val)#x의 κ°’을 y_pred_val에 λ„£μ–΄μ„œ forward
        l = loss(x_val, y_val)
        l_sum += l#w에 λ”°λ₯Έ loss κ³„μ‚°
        print("\t",x_val, y_val, y_pred_val, 1)
    print("MSE= ", l_sum / 3)#mse : ν‰κ·  μ œκ³±κ·Ό μ˜€μ°¨
    w_list.append(w)
    mse_list.append(l_sum/3)
    
    plt.plot(w_list, mse_list)
    plt.ylabel('loss')
    plt.xlabel('w')
    plt.show()
        
    
cs



weight에 λ”°λ₯Έ mse(ν‰κ· μ œκ³±μ˜€μ°¨) κ°€ 좜λ ₯되게 ν•΄ λ³΄μ•˜λ‹€.



2.0 으둜 갈수둝 μ˜€μ°¨κ°€ μ€„μ–΄λ“œλŠ” μ΄μ°¨ν•¨μˆ˜κ°€ λ‚˜μ˜€λŠ” 것을 λ³Ό 수 μžˆμ—ˆλ‹€.

λ°˜μ‘ν˜•