import tensorflow as tf
import numpy as np
x_input = np.array([[1,2,3,4,5]])
y_input = np.array([[10]])
x = tf.placeholder(tf.float32, [None, 5])
y = tf.placeholder(tf.float32, [None, 1])
W = tf.Variable(tf.zeros([5, 1]))
b = tf.Variable(tf.zeros([1]))
y_pred = tf.matmul(x, W)+b
loss = tf.reduce_sum(tf.pow((y-y_pred), 2))
train = tf.train.GradientDescentOptimizer(0.0001).minimize(loss)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
for i in range(10):
feed_dict = {x: x_input, y: y_input}
sess.run(train, feed_dict=feed_dict)
sess = tf.Session()
sess.run(init)
for i in range(10):
feed_dict = {x: x_input, y: y_input}
_, loss_value = sess.run([train, loss], feed_dict=feed_dict)
print(loss_value)
100.0
97.77255
95.594696
93.46538
91.38347
89.34794
87.357765
85.41191
83.5094
81.64925
Created
September 1, 2018 12:57
-
-
Save Orbifold/95e1dc0ffca2be07cbe1cba78b3ca49c to your computer and use it in GitHub Desktop.
TensorFlow hello world
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment