编辑:
我有一些楠在我的数据,但anwser是正确的,你有一些噪音来初始化你的体重! 谢谢!这些nan从哪里来?
我做我的第一个脚本与tensorflow。我有一些问题的印刷价值,但现在我明白了。 我想尝试一个简单的逻辑回归来开始,我正在研究kaggle泰坦尼克号数据集。
我的问题是,我不知道为什么,但我在我的体重和偏差得到了一些楠所以在我的Y(预测)向量太...
编辑: 我的体重在0初始化,我想是一个空渐变。 按照答案提供我添加
W = tf.truncated_normal([5, 1], stddev=0.1)
,而不是
W = tf.Variable(tf.zeros([5, 1])) #weight for softmax
,但我仍然有一些问题。我的b变量提供唉变量仍然楠,当我试图同样的事情BI得到了以下错误: ValueError异常:无变量优化
我尝试了几种方法来分配我的张量biais [1,1],但它看起来像我丢失的东西我
貌似y是因为楠交叉熵是楠由于b是南... :( END - 编辑
我在读这篇文章(Why does TensorFlow return [[nan nan]] instead of probabilities from a CSV file?)谁给我一个提示,我cross entropy calcul 0 * log(0)return nan所以我应用了给定的解决方案,即添加1e-50像:
cross_entropy = -tf.reduce_sum(y_ * tf.log(y + 1e-50) )
不幸的是这不是我想这个问题,我仍然有楠处处:(
这是interisting(我猜的)我很简单的模型的一部分:
x = tf.placeholder(tf.float32, [None, 5]) #placeholder for input data
W = tf.truncated_normal([5, 1], stddev=0.1)
b = tf.Variable(tf.zeros([1])) # no error but nan
#b = tf.truncated_normal([1, 1], stddev=0.1) Thow the error descript above
#b = [0.1] no error but nan
y = tf.nn.softmax(tf.matmul(x, W) + b) #our model -> pred from model
y_ = tf.placeholder(tf.float32, [None, 1])#placeholder for input
cross_entropy = -tf.reduce_sum(y_*tf.log(y)) # crossentropy cost function
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
init = tf.initialize_all_variables() # create variable
sess = tf.InteractiveSession()
sess.run(init)
testacc = []
trainacc = []
for i in range(15):
batch_xs = train_input[i*50:(i + 1) * 50]
batch_ys = train_label[i*50:(i + 1) * 50]
result = sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
correct_prediction = tf.equal(y,y_)
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run([accuracy, W, y] , feed_dict={x: test_input, y_: test_label}))
它返回我一个0.0的准确性当然和2阵列之后我试图在任何地方打印值,但是无处不在:'(
有人有想法吗?我可能忘了什么事或做错
的事情是,我试图与MNIST(谷歌教程)类似的脚本包含数据和它的作品(没有男)。我用熊猫阅读csv文件得到我的数据。
感谢您的阅读!
您好,感谢您的回答, 我编辑我的帖子上面,它实际上适用于我的体重,但是当我做同样的偏见,但它不起作用!它引发了我在编辑部分描述的一些错误,并且我刷新了代码。 你有什么想法吗?感谢您的回答:) –
我有一些与nan的数据,这是问题...谢谢你的答案! –