my code for linear regression
with 3 features . i had tried to execute in terminal . i got the following error
value error:setting an array with a sequence
import tensorflow as tf
INPUT_XOR=[[1,72,50,33.6],[1,66,31,26.6],[1,64,32,23.3],
[1,66,21,28.1],[1,40,33,43.1],[1,74,30,25.6],[1,50,26,31.0],
[1,0,29,35.3],[1,70,53,30.5],[96,54,0]]
OUTPUT_XOR=[[148],[85],[183],[89],[137],[116],[78],[115],[197],[125]]
n_nodes_hl1=10
n_nodes_hl2=1
batch_size=100
x=tf.placeholder('float',[10,4])
y=tf.placeholder('float',[10,1])
def train_neural_network(x):
hidden_1_layer=
{'weights':tf.Variable(tf.random_uniform([4,n_nodes_hl1],-1.0,1.0)),
'biases':tf.Variable(tf.zeros([n_nodes_hl1]))}
output_layer=
{'weights':tf.Variable(tf.random_uniform([n_nodes_hl1,n_nodes_hl2],
-1.0,1.0)),
'biases':tf.Variable(tf.zeros([n_nodes_hl2]))}
l1=tf.add(tf.matmul(x,hidden_1_layer['weights']),hidden_1_layer['biase
s'])
l1=tf.nn.relu(l1)
output=tf.add(tf.matmul(l1,output_layer['weights']),output_layer['biases'])
output=tf.sigmoid(output)
prediction=output
cost=tf.reduce_mean(tf.squared_difference(prediction,y))
optimizer=tf.train.GradientDescentOptimizer(0.01).minimize(cost)
hm_epochs=10000
with tf.Session() as sess:
init_op=tf.global_variables_initializer()
sess.run(init_op)
for epoch in range(100001):
epoch_loss=0
sess.run(optimizer, feed_dict={x:INPUT_XOR, y:OUTPUT_XOR})
if epoch%10000==0:
c=sess.run(cost, feed_dict={x:INPUT_XOR, y:OUTPUT_XOR})
#epoch_loss+=c
print('Epoch:', epoch, 'completed out of ',hm_epochs
,'cost', c)
print('_'*80)
for element in sess.run(prediction, feed_dict=
{x:INPUT_XOR, y:OUTPUT_XOR}):
print(' ', element)
correct=tf.equal(tf.argmax(prediction,1),tf.argmax(y,1))
accuracy=tf.reduce_mean(tf.cast(correct,'float'))
print('Accuracy:',accuracy.eval({x:INPUT_XOR, y:OUTPUT_XOR}))
train_neural_network(x)
output:
Traceback (most recent call last): File "", line 1, in File "", line 19, in train_neural_network File "/home/vj/tensorflow/local/lib/python2.7/site- packages/tensorflow/python/client/session.py", line 895, in run run_metadata_ptr) File "/home/vj/tensorflow/local/lib/python2.7/site- packages/tensorflow/python/client/session.py", line 1093, in _run np_val = np.asarray(subfeed_val, dtype=subfeed_dtype) File "/home/vj/tensorflow/local/lib/python2.7/site- packages/numpy/core/numeric.py", line 531, in asarray return array(a, dtype, copy=False, order=order) ValueError: setting an array element with a sequence.
please help me to sort out this error