【发布时间】:2016-04-04 08:41:01
【问题描述】:
我正在使用 tensorflow 编写我的第一个脚本。 我想尝试一个简单的逻辑回归开始,我正在研究 kaggle titanic 数据集。
我的问题是我无法打印一些张量来调试我做错的事情。
我阅读了这篇文章 (How to print the value of a Tensor object in TensorFlow?),但我不明白如何打印张量。 :(
我很确定很接近,但无法弄清楚
让我告诉你我在做什么;
train = pd.read_csv("./titanic_data/train.csv", dtype={"Age": np.float64}, )
# My parameters for start
train_input = train[['Pclass','Age','SibSp','Parch','Fare']];
train_label = train['Survived']
train_label = train_label.reshape(891, 1)
#split my dataset
test_input = train_input[800:891]
test_label = train_label[800:891]
train_input = train_input[0:800]
train_label = train_label[0:800]
x = tf.placeholder(tf.float32, [None, 5]) #placeholder for input data
W = tf.Variable(tf.zeros([5, 1])) #weight for softmax
b = tf.Variable(tf.zeros([1])) # bias for softmax
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_)
想在这里打印
**#correct_prediction.eval()
#trying to print correct_prediction or y so i can see what is my model actualy doing**
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
trainacc.append(sess.run(accuracy, feed_dict={x: train_input, y_: train_label}))
testacc.append(sess.run(accuracy, feed_dict={x: test_input, y_: test_label}))
我想我所做的一切都是基础。如果有人可以帮助我,我会很棒!我有点卡住了,无法改进我的模型。如果您愿意,请随时告诉我好的做法:)
感谢您阅读本文!
【问题讨论】:
标签: tensorflow