I have data that is structured in a csv file. I want to be able to predict whether column 1 is going to be a 1 or a 0 given all other columns. How do I go about training the program (preferably using Neural Networks) to use all of the given data in order to make that prediction. Is there code that someone can show me? I've tried feeding it numpy.ndarray
, FIF0Que
(sorry if I spelt that wrong), and a DataFrame
; nothing has worked yet. Here is the code I am running until I get the error-
import tensorflow as tf
import numpy as np
from numpy import genfromtxt
data = genfromtxt('cs-training.csv',delimiter=',')
x = tf.placeholder("float", [None, 11])
W = tf.Variable(tf.zeros([11,2]))
b = tf.Variable(tf.zeros([2]))
y = tf.nn.softmax(tf.matmul(x,W) + b)
y_ = tf.placeholder("float", [None,2])
cross_entropy = -tf.reduce_sum(y_*tf.log(y))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
for i in range(1000):
batch_xs, batch_ys = data.train.next_batch(100)
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
At which point I run into this error-
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-128-b48741faa01b> in <module>()
1 for i in range(1000):
----> 2 batch_xs, batch_ys = data.train.next_batch(100)
3 sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
AttributeError: 'numpy.ndarray' object has no attribute 'train'
Any help is greatly appreciated. All I need to do is predict whether column 1 is going to be a 1 or a 0. Even if all you do is get me past this one error, I should be able to take it from there.
EDIT: This is what the csv looks like when I print it out.
[[1,0.766126609,45,2,0.802982129,9120,13,0,6,0,2],
[0,0.957151019,40,0,0.121876201,2600,4,0,0,0,1],
[0,0.65818014,38,1,0.085113375,3042,2,1,0,0,0],
[0,0.233809776,30,0,0.036049682,3300,5,0,0,0,0]]
I'm trying to predict the first column.