Multinomial Classification Linear Regression을 이용해 예측을 하였고, 이는 100, 200, -10 등의 어떤 하나의 실수 값을 예측 하는데는 유용한 모델이지만 Binary한 모델에는 적합하지 않다는 것을 보았다. 그래서 예측값들을 Logistic Regression을 이용하여 0과 1사이의 수로 압축을 한 다음, 0과 1이라는 Binary한 값으로 예측을 하였다. 이제는 Binary한 구분을 넘어 Multinomial한 구분을 하는 예측을 해보자. 입력 값 X를 넣고, W라는 unit을 가지고 계산을 해서 Z값이 나오고, 이를 Sigmoid 함수에 넣으면 0과 1사이의 값을 가지는 Y bar가 나온다. Logistic Regression을 학습시킨 다는 것은 2개의 ..
Classification Binary한 값을 예측하기 위한 모델: 이메일-스팸메일 구분, 페이스북 타임라인에서 특정 피드 보여주기-숨기기, 신용카드 도난 여부 확인, 주식 시장 예측 Binary한 값의 예측을 Linear Regression을 사용하여 하면 어떻게 될까? 예측값보다 큰 값으로 학습을 진행하면 그래프가 기울어지며 예측을 정확하게 하지 못한다. 따라서 Linear Regression 대신 0과 1 사이의 값으로 압축시켜주는 Sigmoid 함수를 도입한다. g(z) : 시그모이드 함수에 Hypothesis 함수를 합성하여 시그모이드 함수의 Hypothesis함수를 만들면 다음과 같이 나타난다. Linear Regression의 가설과 비용함수를 다시 상기해보자. 가설 : H(x) = Wx+b..
Logistic Regression¶ In [1]: from PIL import Image Image.open('Logistic Regression.png') Out[1]: Training Data¶ In [5]: import 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.float32, shape=[None, 1]) W = tf...
Loading data from file¶ 넘파이를 이용하여 구해보자. In [1]: import numpy as np In [2]: from PIL import Image Image.open('data-01-test-score.png') Out[2]: In [3]: xy = np.loadtxt('data-01-test-score.csv', delimiter=',', dtype=np.float32) # 모두 같은 타입이어야만 가능 x_data = xy[:, 0:-1] y_data = xy[:, [-1]] In [ ]: ##### 슬라이싱 ##### nums = range(5) # range is a built-in function that creates a list of integers print num..
Multi-variable linear regression¶ In [5]: from PIL import Image Image.open('그림3.png') Out[5]: H(x1,x2,x3) = x1w1 + x2w2 + x3w3¶ In [ ]: import tensorflow as tf x1_data = [73., 93., 89., 96., 73.] x2_data = [80., 88., 91., 98., 66.] x3_data = [75., 93., 90., 100., 70.] y_data = [152., 185., 180., 196., 142.] # placeholders for a tensor that will be always fed. x1 = tf.placeholder(tf.float32) x2 =..
Linear Regression의 cost 최소화의 TensorFlow 구현¶ cost함수는 어떻게 생겼을까?¶ In [6]: import tensorflow as tf import matplotlib.pyplot as plt X = [1,2,3] Y = [1,2,3] W =tf.placeholder(tf.float32) # Out hypothesis for linear molde X * W hypothesis = X * W # cost/loss function cost = tf.reduce_mean(tf.square(hypothesis - Y)) #Launch the graph in a session. sess = tf.Session() # Initializes global variables in th..
TensorFlow로 간단한 linear regression을 구현¶ (1) Build graph using TensorFlow operations¶ (2) feed data and run graph (operation) :¶ sess.run(op, feed_dict={x:x_data})¶ (3) update variables in the graph (and return values)¶ In [30]: from PIL import Image Image.open('mechanics.png') Out[30]: (1) Build graph using TensorFlow operations¶ H(x) = Wx + b¶ In [1]: import tensorflow as tf In [4]: # X and Y da..
In [11]: from PIL import Image Image.open('1번.png') Out[11]: TensorFlow Hello World¶ In [2]: import tensorflow as tf In [3]: tf.__version__ Out[3]: '1.13.1' In [4]: # Create a constant op # This op is added as a node to the defalt graph hello = tf.constant('Hello, TensorFlow!') # seart a TF session sess = tf.Session() # run the op and get result print(sess.run(hello)) b'Hello, TensorFlow!' 어떤 그래..