我试图实现一个神经网络来解决分类问题,但是我的程序: _, c = sess.run([train_op, loss_op], feed_dict={X: x_train,Y: y_train})我试图重塑数据并尝试了堆栈中给出的许多解决方案来解决我的问题,但对我不起作用,我想知道我该怎么办?最重要的部分:...n_output = 8n_input = 9 # Max number of input that may have features of one single program################################ Dfine data ####################################from google.colab import filesimport iouploaded = files.upload()x_train_ = pd.read_csv(io.StringIO(uploaded['x_train.csv'].decode('utf-8')), skiprows=1, header=None)uploaded1 = files.upload()y_train_ = pd.read_csv(io.StringIO(uploaded1['y_train.csv'].decode('utf-8')), skiprows=1, header=None)x_train.fillna(-1, inplace=True)x_train = np.array(x_train)y_train = np.array(y_train)################################ Input, weights, biases ######################### tf Graph inputX = tf.placeholder(shape=[None, n_input], dtype=tf.float32)Y = tf.placeholder(shape=[None, n_output], dtype=tf.float32).....################################ Construct model ###############################logits = multilayer_perceptron(X)# Define loss and optimizerloss_op = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=Y))optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate)train_op = optimizer.minimize(loss_op)...# Initializing the variablesinit = tf.global_variables_initializer()with tf.Session() as sess: sess.run(init) # Training cycle for epoch in range(training_epochs): avg_cost = 0. _, c = sess.run([train_op, loss_op], feed_dict={X: x_train,Y: y_train}) ... print("Optimization Finished!")编辑:一旦我打印出来:print(y_train_.head()) 它给出: 00 21 42 83 164 32
2 回答
翻阅古今
TA贡献1780条经验 获得超5个赞
Y = tf.placeholder(shape=[None, n_output], dtype=tf.float32) 所以你的 Y 占位符的形状是 [m, 8]。显然 y_train 构造不正确,请尝试使用 y_train.values() 而不是 np.array(y_train)。
拉丁的传说
TA贡献1789条经验 获得超8个赞
我后来意识到,因为我的 y_train csv 文件只包含一列,所以我必须像这样声明它
Y = tf.placeholder(shape=[None,1], dtype=tf.float32)
我不应该混淆类的数量和如何声明“Y”。
所以就像他说品雪一样,如果我这样声明 Y:
Y = tf.placeholder(shape=[None, n_output], dtype=tf.float32)
我的 Y 占位符的形状是 [m, 8] 而不是 [m,1]。所以我不得不像我在上面的解决方案中提到的那样声明它来修复它。
添加回答
举报
0/150
提交
取消
