본문 바로가기

코딩으로 익히는 Python/모델링

[Python] 11. softmax

728x90
반응형
SMALL
import numpy as np

def fn(x):
    print(x/x.sum())

 

a = np.array([2.0,1.0,0.1])
fn(a)
[OUT]:

[0.64516129 0.32258065 0.03225806]

 

-> 전체 합에서 차지하는 비율


Softmax

 

def softmax(x):
    e = np.exp(x)
    print(e)
    print( e/np.sum(e))

 

a = np.array([2.0,1.0,0.1])
softmax(a)
[OUT]:

[7.3890561  2.71828183 1.10517092]
[0.65900114 0.24243297 0.09856589]

 

-> e^x를 하여 확률이 높은곳에 가중치를 더 주는 형식


review
- 다중분류 시 사용되는 softmax
728x90
반응형
LIST