|
5 | 5 | Project: https://github.com/aymericdamien/TensorFlow-Examples/ |
6 | 6 | ''' |
7 | 7 |
|
| 8 | +from __future__ import print_function |
| 9 | + |
8 | 10 | import tensorflow as tf |
9 | 11 | import numpy |
10 | 12 | import matplotlib.pyplot as plt |
|
53 | 55 | #Display logs per epoch step |
54 | 56 | if (epoch+1) % display_step == 0: |
55 | 57 | c = sess.run(cost, feed_dict={X: train_X, Y:train_Y}) |
56 | | - print "Epoch:", '%04d' % (epoch+1), "cost=", "{:.9f}".format(c), \ |
57 | | - "W=", sess.run(W), "b=", sess.run(b) |
| 58 | + print("Epoch:", '%04d' % (epoch+1), "cost=", "{:.9f}".format(c), \ |
| 59 | + "W=", sess.run(W), "b=", sess.run(b)) |
58 | 60 |
|
59 | | - print "Optimization Finished!" |
60 | | - training_cost = sess.run(cost, feed_dict={X: train_X, Y: train_Y}) |
61 | | - print "Training cost=", training_cost, "W=", sess.run(W), "b=", sess.run(b), '\n' |
| 61 | + print("Optimization Finished!" |
| 62 | + training_cost = sess.run(cost, feed_dict={X: train_X, Y: train_Y})) |
| 63 | + print("Training cost=", training_cost, "W=", sess.run(W), "b=", sess.run(b), '\n') |
62 | 64 |
|
63 | 65 | #Graphic display |
64 | 66 | plt.plot(train_X, train_Y, 'ro', label='Original data') |
|
70 | 72 | test_X = numpy.asarray([6.83, 4.668, 8.9, 7.91, 5.7, 8.7, 3.1, 2.1]) |
71 | 73 | test_Y = numpy.asarray([1.84, 2.273, 3.2, 2.831, 2.92, 3.24, 1.35, 1.03]) |
72 | 74 |
|
73 | | - print "Testing... (Mean square loss Comparison)" |
| 75 | + print("Testing... (Mean square loss Comparison)") |
74 | 76 | testing_cost = sess.run( |
75 | 77 | tf.reduce_sum(tf.pow(pred - Y, 2)) / (2 * test_X.shape[0]), |
76 | 78 | feed_dict={X: test_X, Y: test_Y}) # same function as cost above |
77 | | - print "Testing cost=", testing_cost |
78 | | - print "Absolute mean square loss difference:", abs( |
79 | | - training_cost - testing_cost) |
| 79 | + print("Testing cost=", testing_cost) |
| 80 | + print("Absolute mean square loss difference:", abs( |
| 81 | + training_cost - testing_cost)) |
80 | 82 |
|
81 | 83 | plt.plot(test_X, test_Y, 'bo', label='Testing data') |
82 | 84 | plt.plot(train_X, sess.run(W) * train_X + sess.run(b), label='Fitted line') |
|
0 commit comments