Skip to content

Commit

Permalink
Update lab-06-1-softmax_classifier.py (hunkim#232)
Browse files Browse the repository at this point in the history
* Update lab-06-1-softmax_classifier.py

More simplified code and added missing output.

* Update lab-06-1-softmax_classifier.py
  • Loading branch information
qoocrab authored and kkweon committed Jan 13, 2019
1 parent 796da36 commit 107d2eb
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions lab-06-1-softmax_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,48 @@
sess.run(tf.global_variables_initializer())

for step in range(2001):
sess.run(optimizer, feed_dict={X: x_data, Y: y_data})
if step % 200 == 0:
print(step, sess.run(cost, feed_dict={X: x_data, Y: y_data}))
_, cost_val = sess.run([optimizer, cost], feed_dict={X: x_data, Y: y_data})

print('--------------')
if step % 200 == 0:
print(step, cost_val)

print('--------------')
# Testing & One-hot encoding
a = sess.run(hypothesis, feed_dict={X: [[1, 11, 7, 9]]})
print(a, sess.run(tf.argmax(a, 1)))

print('--------------')

b = sess.run(hypothesis, feed_dict={X: [[1, 3, 4, 3]]})
print(b, sess.run(tf.argmax(b, 1)))

print('--------------')

c = sess.run(hypothesis, feed_dict={X: [[1, 1, 0, 1]]})
print(c, sess.run(tf.argmax(c, 1)))

print('--------------')

all = sess.run(hypothesis, feed_dict={
X: [[1, 11, 7, 9], [1, 3, 4, 3], [1, 1, 0, 1]]})
all = sess.run(hypothesis, feed_dict={X: [[1, 11, 7, 9], [1, 3, 4, 3], [1, 1, 0, 1]]})
print(all, sess.run(tf.argmax(all, 1)))

'''
--------------
[[ 1.38904958e-03 9.98601854e-01 9.06129117e-06]] [1]
--------------
[[ 0.93119204 0.06290206 0.0059059 ]] [0]
--------------
[[ 1.27327668e-08 3.34112905e-04 9.99665856e-01]] [2]
--------------
[[ 1.38904958e-03 9.98601854e-01 9.06129117e-06]
[ 9.31192040e-01 6.29020557e-02 5.90589503e-03]
[ 1.27327668e-08 3.34112905e-04 9.99665856e-01]] [1 0 2]
0 6.926112
200 0.6005015
400 0.47295815
600 0.37342924
800 0.28018373
1000 0.23280522
1200 0.21065344
1400 0.19229904
1600 0.17682323
1800 0.16359556
2000 0.15216158
-------------
[[1.3890490e-03 9.9860185e-01 9.0613084e-06]] [1]
-------------
[[0.9311919 0.06290216 0.00590591]] [0]
-------------
[[1.2732815e-08 3.3411323e-04 9.9966586e-01]] [2]
-------------
[[1.3890490e-03 9.9860185e-01 9.0613084e-06]
[9.3119192e-01 6.2902197e-02 5.9059085e-03]
[1.2732815e-08 3.3411323e-04 9.9966586e-01]] [1 0 2]
'''

0 comments on commit 107d2eb

Please sign in to comment.