티스토리 뷰
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import tensorflow as tf X = tf.placeholder(tf.float32, shape=[None]) //shape이 None인 placeholder Y = tf.placeholder(tf.float32, shape=[None]) W = tf.Variable(tf.random_normal([1]), name = 'weight') b = tf.Variable(tf.random_normal([1]), name = 'bias') Hypothesis = x_train * W +b //define Hypothesis cost = tf.reduce_mean(tf.square(Hypothesis - y_train)) optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01) //경사 하강법 , 학습비율 0.1 train = optimizer.minimize(cost) // optimizer의 minimize 함수 호출 하여 cost를 minimize함 sess = tf.Session() sess.run(tf.global_variables_initializer()) //W,b 와 같은 Variable을 initialize 함 for step in range(2001): cost_val, W_val, b_val, _ = sess.run([cost, W, b, train], feed_dict = {X: [1,2,3,4,5], Y: [2.1,3.1,4.1,5.1,6.1]}) if step %20 ==0: print(step ,cost_val ,W_val ,b_val) | cs |
'Programming > Deep Learning' 카테고리의 다른 글
퍼셉트론 AND , OR , NAND게이트 (0) | 2018.03.20 |
---|---|
퍼셉트론 (0) | 2018.03.20 |
Linear Regression 구현 (0) | 2018.03.19 |
Linear Regression의 이해 (0) | 2018.03.18 |
기본적인 Tenworflow (0) | 2018.03.18 |
댓글