본문 바로가기
반응형

2018/058

[ML] Fancy Softmax Classifier Fancy Softmax Classifier 우선 one_hot과 reshape에 대해서 알아보자. one_hot encoding은 softmax로 구한 값 중 가장 큰 값을 1, 그 외의 값을 0으로 encoding한다. reshape은 무엇일까? 위 그림을 보자. 맨 끝에 Y값을 보면 0~6 까지의 값이 나와있다. 이것은 one_hot의 형태가 아니다. 그러므로 이 값을 reshape을 사용하여 one_hot 형태로 바꿔줄 수 있다. 예를들어 0은 1000000 으로, 3은 00010000 으로 말이다. [[0], [3]]은 [[1000000], [0001000]]이 된다. 다시 한번 보면, 처음 Y의 값은 shape(?, 1)이 된다. 행은 ? 열은 1 one_hot을 한번 하게 되면 [[[1000.. 2018. 5. 31.
[ML] Softmax classifier Softmax의 기본 Scores --> probabilities Softmax 'ONE-HOT' Encoding을 통해 가장 큰 값을 제외한 값을 0으로 바꾸고 가장 큰 값을 1로 바꿈. Softmax Classifier의 Cost function 값이 일치하면 0, 그렇지 않으면 무한대로 간다. arg_max : 새로운 값(리스트)를 던져주고 함수의 인자에 따라 몇 번째 인덱스에 존재하는지를 반환해주는 함수. arg_max(a, 1)의 뜻은 a에서 1번째 값, 즉 가장 큰 값을 찾으라는 것을 말한다. [1, 11, 7, 9]에서 가장 큰 값의 인덱스는 1이기 때문에 1을 반환하게 된다. 소스 코드 1234567891011121314151617181920212223242526272829303132333.. 2018. 5. 29.
[ML] Logistic Classification 소스 코드 logistic_regression.py123456789101112131415161718192021222324252627282930313233343536373839404142434445464748# Lab 5 Logistic Regression Classifierimport tensorflow as tf x_data = [[1, 2], [2, 3], [3, 1], [4, 3], [5, 3], [6, 2]]y_data = [[0], [0], [0], [1], [1], [1]] # placeholders for a tensor that will be always fed.X = tf.placeholder(tf.float32, shape=[None, 2])Y = tf.placeholder(tf.flo.. 2018. 5. 20.
[ML] TensorFlow로 파일에서 데이터 읽어오기 우선 파일을 읽어오는 소스는 다음과 같다. file_input_linear_regression.py12345678910111213141516171819202122232425262728293031323334# Lab 4 Multi-variable linear regressionimport tensorflow as tfimport numpy as npxy = np.loadtxt('data-01-test-score.csv', delimiter=',', dtype=np.float32)x_data = xy[:, 0:-1]y_data = xy[:, [-1]]# placeholders for a tensor that will be always fed.X = tf.placeholder(tf.float32, shape=.. 2018. 5. 16.
[ML] multi-variable linear regression multi-variable linear regression x의 값이 여러개이면 위와 같이 여러번 곱해주면 된다. 하지만 단점이 있다. 값이 100, 1000 ... 너무 많아지면 연산이 매우 복잡해진다. 우리는 이러한 문제를 Matrix를 이용하여 해결할 수 있다. 기본 원리는 아래와 같다. Matrix를 사용하면 n개를 편하게 연산할 수 있다. ※ 주의사항tensorflow 계산할 때는 H(x) = XW로 해주자! tensorflow 소스 1234567891011121314151617181920212223242526272829303132333435363738394041# Lab 4 Multi-variable linear regressionimport tensorflow as tf x1_data = [.. 2018. 5. 8.
[ML] Linear Regression의 cost 최소화 cost를 미분 minimzing_cost_gradient_update.py1234567891011121314151617181920212223242526272829import tensorflow as tf x_data = [1, 2, 3]y_data = [1, 2, 3] W = tf.Variable(tf.random_normal([1]), name='weight')X = tf.placeholder(tf.float32)Y = tf.placeholder(tf.float32) # Our hypothesis for linear model X * Whypothesis = X * W # cost/loss functioncost = tf.reduce_mean(tf.square(hypothesis - Y)) # Min.. 2018. 5. 8.
반응형