在jupyter nootbook中编辑和运行
一 TensorFlow
步骤:
一。import tensorflow as tf
二。载入数据
(数据分批)
三。定义placeholder(之后传入训练集)
x = tf.placeholder(tf.float32, [维度], name = "")
四。定义结构和参数(w,b)
写出预测函数z = (激活函数(wx + b))
可以进行dropout(防止过拟合)
第四步每一层神经网络都要定义一次(最后一层的激活函数一般和前面不一样)
w = tf.Variable(tf.zeros([]))
wx_plus_b = tf.matmul(w, x) + b
L1 = tf.nn.激活函数(wx_plus_b) (最后一层命名为prediction)
#dropout
keep_prob=tf.placeholder(tf.float32)(或直接定义为一个常数)
L1_drop = tf.nn.dropout(L1,keep_prob)
五。定义代价函数(二次代价函数,交叉熵代价函数)
loss = tf.reduce_mean(tf.square(y-prediction))