-
-
Save sjain07/a45ef4ff088e01abbcc89e91b030b380 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = tf.placeholder("float", shape=[None, x_size]) | |
y = tf.placeholder("float", shape=[None, y_size]) | |
w_1 = tf.Variable(tf.random_normal((x_size, h_size), stddev=0.1)) | |
w_2 = tf.Variable(tf.random_normal((h_size, y_size), stddev=0.1)) | |
h = tf.nn.sigmoid(tf.matmul(X, w_1)) | |
yhat = tf.matmul(h, w_2) | |
predict = tf.argmax(yhat, dimension=1) | |
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(yhat, y)) | |
updates = tf.train.GradientDescentOptimizer(0.01).minimize(cost) | |
sess = tf.InteractiveSession() | |
init = tf.initialize_all_variables() | |
sess.run(init) | |
for epoch in range(1000): | |
for i in range(len(train_X)): | |
sess.run(updates, feed_dict={X: train_X[i: i + 1], y: train_y[i: i + 1]}) | |
train_accuracy = numpy.mean(numpy.argmax(train_y, axis=1) == sess.run(predict, feed_dict={X: train_X, y: train_y})) | |
test_accuracy = numpy.mean(numpy.argmax(test_y, axis=1) == sess.run(predict, feed_dict={X: test_X, y: test_y})) | |
print("Epoch = %d, train accuracy=%.2f%%, test accuracy=%.2f%%" % (epoch+1,100.*train_accuracy,100.* test_accuracy)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment