본문 바로가기

반응형

잡다한 IT/머신러닝 & 딥러닝

06-2. Softemax_zoo_classifier ■ 파일 처리 Softmax 구현 ▶ 사용된 텐서플로우 APItf.nn.softmax_cross_entropy_with_logitstf.argmax cost_i = tf.nn.softmax_cross_entropy_with_logits(logits=logits,labels=Y_one_hot)- logits = tf.matmul(X,W)+ b 에서 바로 cost 함수를 얻는다.- hypothesis = tf.nn.softmax(logits) 은 사용하지 않고 예측할 때 사용된다. cost = tf.reduce_mean(cost_i)- 코스트 함수의 평균을 구한다. optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.1).minimize(cost)-.. 더보기
06-1. Softmax classfier ■ Softmax 구현 (Multinomial Logistic Regression) hypothesis = tf.nn.softmax(tf.matmul(X,W)+b)- hypothesis 에서 tf.matmul(X,W)+b 에 tf.nn.softmax 함수 적용 cost = tf.reduce_mean(-tf.reduce_sum(Y*tf.log(hypothesis),axis=1))- Cross Entropy 를 코스트 함수로 사용한다. optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.1).minimize(cost)- learining_rate 를 0.1로 학습함. 1234567891011121314151617181920212223242526272.. 더보기
05-2. Logistic regression diabetes ■ Logistic regression 을 파일로 읽어서 처리한다. xp = np.loadtxt('data-03-diabetes.csv',delimiter=',', dtype=np.float32)- data-03-diabetes.csv 로 부터 데이터를 읽음 x_data = xy[:,0:-1]y_data = xy[:,[-1]]- 데이터 분리 print(x_data.shpae,y_data.shape)- 데이터가 제대로 분리되었는지 확인 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081.. 더보기
05-1. Logistic Regression Classifier ■ sigmoid 함수를 사용한 binary classifier hypothesis = tf.sigmoid(tf.matmul(X,W)+b)- hypothesis 에서 tf.matmul(X,W)+b 에 sigmoid 함수를 적용 cost = -tf.reduce_mean(Y*tf.log(hypothesis)+(1-Y)*tf.log(1-hypothesis))- Cross Entropy 를 코스트 함수로 사용한다.- 1인 경우 Y*tf.log(hypothesis) 가 0으로 수렴하도록 학습- 0인 경우 (1-Y)*tf.log(1-hypothesis) 가 0으로 수렴하도록 학습 train = tf.train.GradientDescentOptimizer(learning_rate=0.01).minimize(cost).. 더보기
04-3. Mulit-variable linear regression with file input ■ 파일로 부터 데이터 입력 받기. xy = np.loadtxt('data-01-test-score.csv',delimiter=',',dtpye=np.float32)- data-01-test-score.csv로 부터 데이터 입력 받음- 데이터간 구분은 ' ' 스페이스로 한다- 데이터 타입은 np.float32 로 설정함 x_data = xy[:,0:-1]- 처음부터 마지막 이전까지의 데이터를 배열 x_data에 저장 y_data = xy[:,[-1]]- 마지막 데이터를 배열 y_data에 저장 print(x_data.shape,x_data,len(x_data)- 원하는대로 x 데이터가 들어왔는지 확인 print(y_data.shape,y_data)- 원하는대로 y 데이터가 들어왔는지 확인 ※ colab .. 더보기
04-2. Multi-variable linear regression with tf.matmul ■ matmul 함수 사용. x_data - 4x3 배열 생성 y_data - 4x1 배열 생성 hypothesis = tf.matmul(X,W)+b- X : 4x3 , Y:3x1 matrix multiplier 수행 후 b와 더함. 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677# Lab04-2 Multi-variable linear regression import tensorflow as tf tf.set_random_seed(777) # for reproducibility x_data = .. 더보기
04-1. Multi-variable linear regression ■ 여러개의 입력이 있는 경우의 linear regression x1_data , x2_data, x3_data , y_data - 여러 입력을 각각의 1행 5열 배열로 처리 hypothesis = x1*w1 + x2*w2 + x3*w3 +b - 여러 입력에 대한 hypothesis 적용 cost_val, hy_val, _ = sess.run([cost,hypothesis,train], feed_dict= {x1:x1_data,x2:x2_data,x3:x3_data,Y:y_data}) - feed_dict 를 통하여 여러 입력을 대입 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525.. 더보기
노드 수? 레이어 수? Question. Answer. 더보기

반응형