Skip to content

Instantly share code, notes, and snippets.

@jw0201
Last active January 13, 2017 07:08
Show Gist options
  • Select an option

  • Save jw0201/2d84f917729e85814fdfb0e1f3748f2f to your computer and use it in GitHub Desktop.

Select an option

Save jw0201/2d84f917729e85814fdfb0e1f3748f2f to your computer and use it in GitHub Desktop.

Revisions

  1. jw0201 revised this gist Jan 13, 2017. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion linear_regreesion_placeholder.py
    Original file line number Diff line number Diff line change
    @@ -25,4 +25,7 @@
    for step in xrange(2001):
    sess.run(train, feed_dict={X:x_data, Y:y_data})
    if step % 20 == 0:
    print step, sess.run(cost, feed_dict={X:x_data, Y:y_data}), sess.run(W), sess.run(b)
    print step, sess.run(cost, feed_dict={X:x_data, Y:y_data}), sess.run(W), sess.run(b)

    print sess.run(hypothesis, feed_dict={X:5})
    print sess.run(hypothesis, feed_dict={X:2.5})
  2. jw0201 created this gist Jan 13, 2017.
    28 changes: 28 additions & 0 deletions linear_regreesion_placeholder.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    import tensorflow as tf

    x_data = [1., 2., 3.]
    y_data = [1., 2., 3.]

    X = tf.placeholder(tf.float32)
    Y = tf.placeholder(tf.float32)

    W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
    b = tf.Variable(tf.random_uniform([1], -1.0, 1.0))

    hypothesis = W * X + b

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

    a = tf.Variable(0.1)
    optimizer = tf.train.GradientDescentOptimizer(a)
    train = optimizer.minimize(cost)

    init = tf.initialize_all_variables()

    sess = tf.Session()
    sess.run(init)

    for step in xrange(2001):
    sess.run(train, feed_dict={X:x_data, Y:y_data})
    if step % 20 == 0:
    print step, sess.run(cost, feed_dict={X:x_data, Y:y_data}), sess.run(W), sess.run(b)