Skip to content

Commit b27f94a

Browse files
qoocrabkkweon
authored andcommitted
Update lab-04-3-file_input_linear_regression.py
1. Add data output and train output example. 2. Change the data output format to make it easier to read.
1 parent 13a3b63 commit b27f94a

File tree

1 file changed

+55
-7
lines changed

1 file changed

+55
-7
lines changed

lab-04-3-file_input_linear_regression.py

+55-7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,24 @@
88
y_data = xy[:, [-1]]
99

1010
# Make sure the shape and data are OK
11-
print(x_data.shape, x_data, len(x_data))
12-
print(y_data.shape, y_data)
11+
print(x_data, "\nx_data shape:", x_data.shape)
12+
print(y_data, "\ny_data shape:", y_data.shape)
13+
14+
# data output
15+
'''
16+
[[ 73. 80. 75.]
17+
[ 93. 88. 93.]
18+
...
19+
[ 76. 83. 71.]
20+
[ 96. 93. 95.]]
21+
x_data shape: (25, 3)
22+
[[152.]
23+
[185.]
24+
...
25+
[149.]
26+
[192.]]
27+
y_data shape: (25, 1)
28+
'''
1329

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

3652
for step in range(2001):
37-
cost_val, hy_val, _ = sess.run(
38-
[cost, hypothesis, train], feed_dict={X: x_data, Y: y_data})
53+
cost_val, hy_val, _ = sess.run([cost, hypothesis, train],
54+
feed_dict={X: x_data, Y: y_data})
3955
if step % 10 == 0:
40-
print(step, "Cost: ", cost_val, "\nPrediction:\n", hy_val)
56+
print(step, "Cost:", cost_val, "\nPrediction:\n", hy_val)
57+
58+
# train output
59+
'''
60+
0 Cost: 21027.0
61+
Prediction:
62+
[[22.048063 ]
63+
[21.619772 ]
64+
...
65+
[31.36112 ]
66+
[24.986364 ]]
67+
10 Cost: 95.976326
68+
Prediction:
69+
[[157.11063 ]
70+
[183.99283 ]
71+
...
72+
[167.48862 ]
73+
[193.25117 ]]
74+
1990 Cost: 24.863274
75+
Prediction:
76+
[[154.4393 ]
77+
[185.5584 ]
78+
...
79+
[158.27443 ]
80+
[192.79778 ]]
81+
2000 Cost: 24.722485
82+
Prediction:
83+
[[154.42894 ]
84+
[185.5586 ]
85+
...
86+
[158.24257 ]
87+
[192.79166 ]]
88+
'''
4189

4290
# Ask my score
43-
print("Your score will be ", sess.run(
44-
hypothesis, feed_dict={X: [[100, 70, 101]]}))
91+
print("Your score will be ", sess.run(hypothesis,
92+
feed_dict={X: [[100, 70, 101]]}))
4593

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

0 commit comments

Comments
 (0)