유튜브/대충 배우는 머신러닝 AI(영상삭제)

8 - regression 실습2

----___<<<<< 2020. 1. 31. 14:18
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

# 재사용을 위한 설정
tf.set_random_seed(777) 

# Data들 x1, x2, x3
x1_data = [73., 93., 89., 96., 73.]
x2_data = [80., 88., 91., 98., 66.]
x3_data = [75., 93., 90., 100., 70.]

# Data y 결과값
y_data = [152., 185., 180., 196., 142.]

# https://gdyoon.tistory.com/5
# 텐서플로우 data type? 변수선언?
x1 = tf.placeholder(tf.float32)
x2 = tf.placeholder(tf.float32)
x3 = tf.placeholder(tf.float32)

Y = tf.placeholder(tf.float32)

w1 = tf.Variable(tf.random_normal([1]), name='weight1')
w2 = tf.Variable(tf.random_normal([1]), name='weight2')
w3 = tf.Variable(tf.random_normal([1]), name='weight3')
b = tf.Variable(tf.random_normal([1]), name='bias')

hypothesis = x1 * w1 + x2 * w2 + x3 * w3 + b


cost = tf.reduce_mean(tf.square(hypothesis - Y))

# https://hreeman.tistory.com/m/97?category=604657
# 1e-5 = 0.00001 
optimizer = tf.train.GradientDescentOptimizer(learning_rate=1e-5)
train = optimizer.minimize(cost)

# 초기화 후 시작
sess = tf.Session()
sess.run(tf.global_variables_initializer())

# 시작
for step in range(3001):
    cost_val, hy_val, _ = sess.run([cost, hypothesis, train],
                                   feed_dict={x1: x1_data, x2: x2_data, x3: x3_data, Y: y_data})
    if step % 100 == 0:
        print(step, "Cost: ", cost_val, "\nPrediction:\n", hy_val)
        
        


 

Prediction의 값이 y_data = [152., 185., 180., 196., 142.] 와 유사하게 나옵니다.

 

 

 

 

참조

[1] - https://github.com/hunkim/DeepLearningZeroToAll/blob/master/lab-04-1-multi_variable_linear_regression.py

 

 

 

 

 

'유튜브 > 대충 배우는 머신러닝 AI(영상삭제)' 카테고리의 다른 글

10 - Logistic Classification  (0) 2020.02.10
9 - regression kaggle 실습  (0) 2020.01.31
7 - regression 실습  (0) 2020.01.31
6 - 가설(Hyposthesis)  (0) 2020.01.31
5 - 회귀(linear regression)  (0) 2020.01.31