<Source>
import tensorflow as tf
xData = [1, 2, 3, 4, 5, 6, 7]
yData = [25000, 55000, 75000, 110000, 128000, 155000, 180000]
W = tf.Variable(tf.random_uniform([1], -100, 100))
b = tf.Variable(tf.random_uniform([1], -100, 100))
X = tf.placeholder(tf.float32)
Y = tf.placeholder(tf.float32)
H = W * X + b
cost = tf.reduce_mean(tf.square(H-Y))
a = tf.Variable(0.01)
optimizer = tf.train.GradientDescentOptimizer(a)
train = optimizer.minimize(cost)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
for i in range(5001):
sess.run(train, feed_dict={X: xData, Y:yData})
if i % 500 == 0:
print(i, sess.run(cost, feed_dict={X: xData, Y:yData}), sess.run(W), sess.run(b))
print(sess.run(H, feed_dict={X: [8]}))
<Result>
0 4598644000.0 [10378.898] [2002.522]
500 8685089.0 [25539.477] [1940.5034]
1000 8633764.0 [25627.793] [1503.1737]
1500 8632681.0 [25640.662] [1439.4463]
2000 8632654.0 [25642.537] [1430.1561]
2500 8632653.0 [25642.807] [1428.8158]
3000 8632650.0 [25642.844] [1428.6323]
3500 8632657.0 [25642.848] [1428.6133]
4000 8632657.0 [25642.848] [1428.6133]
4500 8632657.0 [25642.848] [1428.6133]
5000 8632657.0 [25642.848] [1428.6133]
[206571.39]
'IT칼럼' 카테고리의 다른 글
Top 100 Java Interview Questions with Answers (0) | 2018.09.03 |
---|---|
singleton 이란? (0) | 2018.09.03 |