我有下面的训练网络,
graph = tf.Graph()
with graph.as_default():
tf_train_dataset = tf.constant(X_train)
tf_train_labels = tf.constant(y_train)
tf_valid_dataset = tf.constant(X_test)
weights = tf.Variable(tf.truncated_normal([X_train.shape[1], 1]))
biases = tf.Variable(tf.zeros([num_labels]))
logits = tf.nn.softmax(tf.matmul(tf_train_dataset, weights) + biases)
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits, tf_train_labels))
optimizer = tf.train.GradientDescentOptimizer(0.5).minimize(loss)
train_prediction = tf.nn.softmax(logits)
valid_prediction = tf.nn.softmax(tf.matmul(tf_valid_dataset, weights) + biases)
我做了如下分析,
num_steps = 10
with tf.Session(graph=graph) as session:
tf.initialize_all_variables().run()
print('Initialized')
for step in range(num_steps):
_, l, predictions = session.run([optimizer, loss, train_prediction])
print("Loss: ",l)
print('Training accuracy: %.1f' % sklearn.metrics.accuracy_score(predictions.flatten(), y_train.flatten()))
但它的输出如下
Initialized
Loss: 0.0
Training accuracy: 0.5
Loss: 0.0
Training accuracy: 0.5
X_train的形状为(213403,25),y_train为(213403,1),以处理逻辑。我没有将标签编码为一个热类,因为只有两个类,要么是1类,要么是0类。我也尝试了二次损失函数,它仍然是一样的,同样的事情发生了,损失函数一点也没有减少。我在这里感觉到了一个句法上的错误,但我毫无头绪。
发布于 2016-08-31 01:36:20
您正在将标签作为单个列传递(不进行编码)。模型无法获得作为因子类型的标签。因此,它将您的标签视为连续值。
损失: 0.0表示损失为零。这意味着你的模型非常合适。之所以会发生这种情况,是因为您的标签是连续的(回归函数),并且使用的是softmax_cross_entropy_with_logits丢失函数。
尝试传递标签的一个热编码并检查。
https://stackoverflow.com/questions/39242818
复制相似问题