In [30]:
import tensorflow as tf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pylab import *
from tensorflow.examples.tutorials.mnist import input_data
%matplotlib inline

In [31]:
#read the datasets
train = pd.read_csv("intro_to_ann.csv")

trX, trY, teX, teY = np.array(train.ix[1:400,0:2]), np.array(train.ix[1:400,2:3]),np.array(train.ix[401:500,0:2]), np.array(train.ix[401:500,2:3])

In [32]:
def init_weights(shape):
    return tf.Variable(tf.random_normal(shape, stddev=0.01))

In [33]:
def model(X, w_h, w_h2, w_o): # this network is the same as the previous one except with an extra hidden layer + dropout
    
    h = tf.sigmoid(tf.matmul(X, w_h))

    
    h2 = tf.sigmoid(tf.matmul(h, w_h2))


    return tf.matmul(h2, w_o)

In [34]:
X = tf.placeholder("float", [None, 2])
Y = tf.placeholder("float", [None, 1])

In [35]:
w_h = init_weights([2, 256])
w_h2 = init_weights([256, 256])
w_o = init_weights([256, 1])

In [36]:
py_x = model(X, w_h, w_h2, w_o)

In [37]:
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(py_x, Y))
train_op = tf.train.RMSPropOptimizer(0.001, 0.9).minimize(cost)
predict_op = tf.argmax(py_x, 1)

In [38]:
with tf.Session() as sess:
    # you need to initialize all variables
    tf.initialize_all_variables().run()

    for i in range(100):
        sess.run(train_op, feed_dict={X: trX, Y: trY})
        print(i, np.mean(np.argmax(teY, axis=1) ==
                         sess.run(predict_op, feed_dict={X: teX, Y: teY})))


0 1.0
1 1.0
2 1.0
3 1.0
4 1.0
5 1.0
6 1.0
7 1.0
8 1.0
9 1.0
10 1.0
11 1.0
12 1.0
13 1.0
14 1.0
15 1.0
16 1.0
17 1.0
18 1.0
19 1.0
20 1.0
21 1.0
22 1.0
23 1.0
24 1.0
25 1.0
26 1.0
27 1.0
28 1.0
29 1.0
30 1.0
31 1.0
32 1.0
33 1.0
34 1.0
35 1.0
36 1.0
37 1.0
38 1.0
39 1.0
40 1.0
41 1.0
42 1.0
43 1.0
44 1.0
45 1.0
46 1.0
47 1.0
48 1.0
49 1.0
50 1.0
51 1.0
52 1.0
53 1.0
54 1.0
55 1.0
56 1.0
57 1.0
58 1.0
59 1.0
60 1.0
61 1.0
62 1.0
63 1.0
64 1.0
65 1.0
66 1.0
67 1.0
68 1.0
69 1.0
70 1.0
71 1.0
72 1.0
73 1.0
74 1.0
75 1.0
76 1.0
77 1.0
78 1.0
79 1.0
80 1.0
81 1.0
82 1.0
83 1.0
84 1.0
85 1.0
86 1.0
87 1.0
88 1.0
89 1.0
90 1.0
91 1.0
92 1.0
93 1.0
94 1.0
95 1.0
96 1.0
97 1.0
98 1.0
99 1.0

In [ ]:


In [ ]: