python - ValueError: setting an array element with a sequence. -
i working on classification problem using iris dataset , having trouble valueerror: setting array element sequence. converted dataset numpy.ndarray still having same error here code
import tensorflow tf import numpy np import pandas pd rawdata = pd.read_csv('/home/akki/desktop/tf/iris.csv') print(np.shape(rawdata)) rawdatashuffel = rawdata.reindex(np.random.permutation(rawdata.index)).as_matrix() data = rawdatashuffel[:,range(0,7)] print(np.shape(data)) labels = rawdatashuffel[:,8] print(np.shape(labels)) ############################################################## # 1 hot genration number_of_op_class = 3 lab = np.eye(number_of_op_class) print(lab) #print(type(lab[0])) ########################################################################### # converting label 1 hot in range(0,100): if labels[i] == 'setosa': labels[i] = lab[0] elif labels[i] == 'versicolor': labels[i] = lab[1] elif labels[i] == 'virginica': labels[i] = lab[2] print(labels) print(type(labels)) #labels = np.asarray(labels) train_data = data[range(0,79),:] train_label = labels[range(0,79)] test_data = data[range(80,99),:] test_labels = labels[range(80,99)] #print(test_labels) x = tf.placeholder(tf.float32) y_ = tf.placeholder(tf.float32) w=tf.variable(tf.zeros([8,3])) b=tf.variable(tf.zeros([3])) y = tf.nn.softmax(tf.matmul(x, w) + b) cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y)) #optimiser - train_step = tf.train.adamoptimizer(0.01).minimize(cross_entropy) #calculating accuracy of our model correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) #session parameters sess = tf.interactivesession() #initialising variables init = tf.initialize_all_variables() sess.run(init) #number of interations epoch=2000 step in range(epoch): _, c=sess.run([train_step,cross_entropy], feed_dict={x: train_data, y_: train_label}) if step%500==0 : print(c)
the error getting is
traceback (most recent call last): file "iris.py", line 70, in <module> _, c=sess.run([train_step,cross_entropy], feed_dict={x: train_data, y_: train_label}) file "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 372, in run run_metadata_ptr) file "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 619, in _run np_val = np.array(subfeed_val, dtype=subfeed_dtype) valueerror: setting array element sequence.
Comments
Post a Comment