Skip to content

Commit

Permalink
Update lab-04-3-file_input_linear_regression.py
Browse files Browse the repository at this point in the history
1. Add data output and train output example.
2. Change the data output format to make it easier to read.
  • Loading branch information
qoocrab authored and kkweon committed Jan 10, 2019
1 parent 13a3b63 commit b27f94a
Showing 1 changed file with 55 additions and 7 deletions.
62 changes: 55 additions & 7 deletions lab-04-3-file_input_linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,24 @@
y_data = xy[:, [-1]]

# Make sure the shape and data are OK
print(x_data.shape, x_data, len(x_data))
print(y_data.shape, y_data)
print(x_data, "\nx_data shape:", x_data.shape)
print(y_data, "\ny_data shape:", y_data.shape)

# data output
'''
[[ 73. 80. 75.]
[ 93. 88. 93.]
...
[ 76. 83. 71.]
[ 96. 93. 95.]]
x_data shape: (25, 3)
[[152.]
[185.]
...
[149.]
[192.]]
y_data shape: (25, 1)
'''

# placeholders for a tensor that will be always fed.
X = tf.placeholder(tf.float32, shape=[None, 3])
Expand All @@ -34,14 +50,46 @@
sess.run(tf.global_variables_initializer())

for step in range(2001):
cost_val, hy_val, _ = sess.run(
[cost, hypothesis, train], feed_dict={X: x_data, Y: y_data})
cost_val, hy_val, _ = sess.run([cost, hypothesis, train],
feed_dict={X: x_data, Y: y_data})
if step % 10 == 0:
print(step, "Cost: ", cost_val, "\nPrediction:\n", hy_val)
print(step, "Cost:", cost_val, "\nPrediction:\n", hy_val)

# train output
'''
0 Cost: 21027.0
Prediction:
[[22.048063 ]
[21.619772 ]
...
[31.36112 ]
[24.986364 ]]
10 Cost: 95.976326
Prediction:
[[157.11063 ]
[183.99283 ]
...
[167.48862 ]
[193.25117 ]]
1990 Cost: 24.863274
Prediction:
[[154.4393 ]
[185.5584 ]
...
[158.27443 ]
[192.79778 ]]
2000 Cost: 24.722485
Prediction:
[[154.42894 ]
[185.5586 ]
...
[158.24257 ]
[192.79166 ]]
'''

# Ask my score
print("Your score will be ", sess.run(
hypothesis, feed_dict={X: [[100, 70, 101]]}))
print("Your score will be ", sess.run(hypothesis,
feed_dict={X: [[100, 70, 101]]}))

print("Other scores will be ", sess.run(hypothesis,
feed_dict={X: [[60, 70, 110], [90, 100, 80]]}))
Expand Down

0 comments on commit b27f94a

Please sign in to comment.