1.搭建神经网络基本流程
定义添加神经层的函数 1.训练的数据 2.定义节点准备接收数据 3.定义神经层:隐藏层和预测层 4.定义 loss 表达式 5.选择 optimizer 使 loss 达到最小 然后对所有变量进行初始化,通过 sess.run optimizer,迭代 1000 次进行学习: import tensorflow as tf import numpy as np # 添加层 def add_layer(inputs, in_size, out_size, activation_function=None): # add one more layer and return the output of this layer Weights = tf.Variable(tf.random_normal([in_size, out_size])) biases = tf.Variable(tf.zeros([1, out_size]) + 0.1) Wx_plus_b = tf.matmul(inputs, Weights) + biases if activation_function is None: outputs = Wx_plus_b else: outputs = activation_function(Wx_plus_b) return outputs # 1.训练的数据 #