在数据加工好以后,我们用TensorFlow做简单的预测。
按之前的做法去读取并加载数据
data,date= dp.readData()
train,test,trainLables,testLabels= dp.normalization(data)
然后添加变量和参数
x = tf.placeholder("float",[None,109])
w = tf.Variable(tf.random_normal([109,21]))
b = tf.Variable(tf.random_normal([21]))
y = tf.nn.softmax(tf.matmul(x,w)+b)
y_ = tf.placeholder("float",[None,21])
损失函数为交叉熵,y+1e-9为了保证交叉熵不为空,不加1e-9则无法继续计算:
#损失函数
cross_entropy = -tf.reduce_sum(y_*tf.log(y+1e-9))
采用动态学习率,随步数进行递减
#设定学习率随时间递减
global_step = tf.Variable(0, trainable=False)
initial_learning_rate = 0.0001 #初始学习率
learning_rate = tf.train.exponential_decay(initial_learning_rate,