【发布时间】:2018-12-22 04:20:11
【问题描述】:
我一直在尝试像往常一样使用训练/测试数据训练模型。我能够得到我的准确性、成本+有效的准确性和成本。所以我认为模型是有效的,结果是 85% 就足够了。
现在,在我完成训练/测试数据后,我有一个 csv 文件,它具有相同类型和结构的数据,但没有一列(默认 - 指示客户是否会付款或延迟)。我试图用模型预测这个值。我正在烦恼如何插入这些数据并返回丢失的列。
问题部分:
这是我用于恢复和预测新数据的代码 -> (y_pred [5100x41])
with tf.Session() as sess:
saver = tf.train.import_meta_graph('my_test_model101.meta')
print("Model found.")
saver.restore(sess, tf.train.latest_checkpoint('./'))
print("Model restored compl.")
z = tf.placeholder(tf.float32, shape= (None,5100))
y_pred= y_pred.as_matrix()
output =sess.run(z,feed_dict={x: y_pred})
print(output)
谁能帮我理解我在这里做错了什么?!!!
错误信息是:
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder_4' with dtype float and shape [?,5100]
[[Node: Placeholder_4 = Placeholder[dtype=DT_FLOAT, shape=[?,5100], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
期待:
我的输入 [5100 x 41] 但最后一列最初具有 Nan 值,我希望它具有应该是 0 或 1 的预测值。
查看经过训练的模型架构:
模型架构:
# Number of input nodes.
input_nodes = 41
# Multiplier maintains a fixed ratio of nodes between each layer.
mulitplier = 3
# Number of nodes in each hidden layer
hidden_nodes1 = 41
hidden_nodes2 = round(hidden_nodes1 * mulitplier)
hidden_nodes3 = round(hidden_nodes2 * mulitplier)
# Percent of nodes to keep during dropout.
pkeep = tf.placeholder(tf.float32)
# input
x = tf.placeholder(tf.float32, [None, input_nodes])
# layer 1
W1 = tf.Variable(tf.truncated_normal([input_nodes, hidden_nodes1], stddev = 0.15))
b1 = tf.Variable(tf.zeros([hidden_nodes1]))
y1 = tf.nn.sigmoid(tf.matmul(x, W1) + b1)
# layer 2
W2 = tf.Variable(tf.truncated_normal([hidden_nodes1, hidden_nodes2], stddev = 0.15))
b2 = tf.Variable(tf.zeros([hidden_nodes2]))
y2 = tf.nn.sigmoid(tf.matmul(y1, W2) + b2)
# layer 3
W3 = tf.Variable(tf.truncated_normal([hidden_nodes2, hidden_nodes3], stddev = 0.15))
b3 = tf.Variable(tf.zeros([hidden_nodes3]))
y3 = tf.nn.sigmoid(tf.matmul(y2, W3) + b3)
y3 = tf.nn.dropout(y3, pkeep)
# layer 4
W4 = tf.Variable(tf.truncated_normal([hidden_nodes3, 2], stddev = 0.15))
b4 = tf.Variable(tf.zeros([2]))
y4 = tf.nn.softmax(tf.matmul(y3, W4) + b4)
# output
y = y4
y_ = tf.placeholder(tf.float32, [None, 2])
构建模型后,我知道您需要添加占位符来存储您要查找的内容。所以:
# Parameters
training_epochs = 5 # These proved to be enough to let the network learn
training_dropout = 0.9
display_step = 1 # 10
n_samples = y_train.shape[0]
batch_size = 2048
learning_rate = 0.001
# Cost function: Cross Entropy
cost = -tf.reduce_sum(y_ * tf.log(y))
# We will optimize our model via AdamOptimizer
optimizer = tf.train.AdamOptimizer(learning_rate).minimize(cost)
# Correct prediction if the most likely value (default or non Default) from softmax equals the target value.
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
到目前为止一切正常,我保存了模型。我能够恢复这个模型(打印变量并且一切都在那里---所以恢复很好)
【问题讨论】:
-
到底是什么问题?请制定一个Minimal, Complete, and Verifiable example,其中仅包含与您的问题相关的代码,并清楚说明您期望发生什么以及实际发生什么(错误消息、堆栈跟踪等)。
-
问题已编辑。但是需要有很长的代码部分才能理解我构建模型的方式
标签: python tensorflow machine-learning python-3.6