Gradient descent(경사하강법, 경사하강알고리즘) - 텐서플로우(tensorflow)
경사 하강 알고리즘, 경사 하강법Cost(W,b)의 값을 최소화 하는 W,b값을 구함.import tensorflow as tfx_data = [?, ?, ?, ?, ?]y_data = [?, ?, ?, ?, ?]with tf.GradientTape() as tape: hypo = W * x_data + b cost = tf.reduce_mean(tf.square(hypo - y_data))W_grad, b_grad = tape.gradient(cost, [W,b])with tf.GradientTape() as tape:Gradient(기울기) Tape(기록)이후 tape에 gradient메서드를 실행하여 cost에 대한 W와b의 편미분 값을 tuple로 전달.learning rate기울기 값..
2020. 5. 20.
Linear Regression(선형회귀) 구현 및 Cost의 최소화 - 텐서플로우(tensorflow)
import tensorflow as tf x_data = [1, 2, 3, 4, 5] y_data = [1, 2, 3, 4, 5] W = tf.Variable(3.5) b = tf.Variable(1.0) # hypothesis = W * x + b hypo = W * x_data + b H(x) = 가설함수 hypotthesis라고 하며 파이썬(tensorflow)에서 구현할수 있도록 변경 # cost = (hypo - y_data) ** 2 cost = tf.reduce_mean(tf.square(hypo - y_data)) 코스트함수. 가설에 의한 출력 - 실제출력 한 값의 제곱값들의 평균 tf.reduce_mean() v = [1., 2., 3., 4.] tf.reduce_mean(v) # 2...
2020. 5. 19.