ak_1
ak_1

Reputation: 183

how to read csv file and apply it to tensor flow

I am new to tensor flow i was trying to learn how to read data in a csv containin two features and one label and got stuck with the following error

I here by attach the csv file

df=pd.read_csv("intro_to_ann.csv")

X=tf.placeholder("float",[None,2])
y_=tf.placeholder("float",2)


W = tf.Variable(tf.zeros([2,2]))
print(W)
b = tf.Variable(tf.zeros([2]))
print(b)
y= tf.sigmoid(tf.matmul(X, W) + b)#predicted value


error = tf.square(y - y_)
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(error)

init = tf.initialize_all_variables()

errors = []
with tf.Session() as sess:
sess.run(init)
 X_data, Y_data = np.array(df.ix[:,0:2]), np.array(df.ix[:,2])
for epoch in range(training_epochs):
    for (x_d,y_d) in zip(X_data,Y_data):
        print(x_d)
        print(y_d)
        sess.run(optimizer, feed_dict={X:x_d,y_:y_d})

I got this error

ValueError: Cannot feed value of shape (2,) for Tensor 'Placeholder_33:0', which has shape '(2, 2)'

Upvotes: 2

Views: 1592

Answers (1)

Dmytro Danevskyi
Dmytro Danevskyi

Reputation: 3159

You redefined y in your code. Pick different names for placeholder and data variable. It should work OK.

Upvotes: 1

Related Questions