求助tensorflow导入csv数据及进一步归一化
本人python小白,白又白,自学几天神经网络,虽然有些困难,但乐在其中,研究tensorflow导入csv数据及归一化问题时,遇到一个问题,向各位大神请教,请不吝赐教。本文借鉴了CSDN中各位的代码,如有借用不当之处,或者代码写的繁琐等问题,也请各位批评指教,十分感谢!
研究了tensorflow导入csv数据,基本有些认识了,这是我根据论文需要和具体数据特征,写的代码。
import tensorflow as tf
filename_queue = tf.train.string_input_producer(["E:/XXXX/XXXXXX/BPNN(no header).csv"])
reader = tf.TextLineReader()
key,value = reader.read(filename_queue)
record_defaults = [[1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1]]
col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, col13, col14, col15, col16, col17, col18, col19, col20, col21, col22, col23, col24, col25, col26, col27 = tf.decode_csv(value, record_defaults = record_defaults)
features = tf.stack([col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, col13, col14, col15, col16, col17, col18, col19, col20, col21, col22, col23, col24, col25, col26])
init_op = tf.global_variables_initializer()
local_init_op = tf.local_variables_initializer()
with tf.Session() as sess:
sess.run(init_op)
sess.run(local_init_op)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
try:
for i in range(1515):
example, label = sess.run([features, col27])
print(example)
# print(label)可以选择打印标签
except tf.errors.OutOfRangeError:
print ('Done !!!')
finally:
coord.request_stop()
coord.join(threads)
输出之后是这样的:
然后想进一步归一化,发现调用的example只显示最后一行,是因为遍历每一行之后,只记得最后一行吗?不太懂,该如何做呢,麻烦大家指导一下。