为什么我的ANN不学习?

我正在使用一个简单的前馈神经网络进行电力负荷预测。以下是我的代码:

...num_periods = 24f_horizon = 48  #forecast horizon...#RNN designningtf.reset_default_graph()inputs = num_periods    #input vector sizehidden = 100    output = num_periods    #output vector sizelearning_rate = 0.01seed = 128x = tf.placeholder(tf.float32, [None, inputs])y = tf.placeholder(tf.float32, [None, output])weights = {    'hidden': tf.Variable(tf.random_normal([inputs, hidden], seed=seed)),    'output': tf.Variable(tf.random_normal([hidden, output], seed=seed))}biases = {    'hidden': tf.Variable(tf.random_normal([1,hidden], seed=seed)),    'output': tf.Variable(tf.random_normal([1,output], seed=seed))}hidden_layer = tf.add(tf.matmul(x, weights['hidden']), biases['hidden'])hidden_layer = tf.nn.relu(hidden_layer)output_layer = tf.matmul(hidden_layer, weights['output']) + biases['output']cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits = output_layer, labels = y))optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)init = tf.initialize_all_variables()           #initialize all the variablesepochs = 1000     #number of iterations or training cycles, includes both the FeedFoward and Backpropogationmape = []...for st in state.values():        print("State: ", st, end='\n')        with tf.Session() as sess:            init.run()            for ep in range(epochs):                sess.run([optimizer, cost], feed_dict={x: x_batches[st], y: y_batches[st]})        print("\n")

这是我对NSW州得到的输出:cost1cost2

我们可以看到,随着周期的增加,成本在持续上升。这是为什么呢?


回答:

您使用了错误的损失函数,因为电力负荷预测听起来像是回归问题,而交叉熵仅适用于分类问题。

您应该使用均方误差之类的损失函数来代替。

Related Posts

Keras Dense层输入未被展平

这是我的测试代码: from keras import…

无法将分类变量输入随机森林

我有10个分类变量和3个数值变量。我在分割后直接将它们…

如何在Keras中对每个输出应用Sigmoid函数?

这是我代码的一部分。 model = Sequenti…

如何选择类概率的最佳阈值?

我的神经网络输出是一个用于多标签分类的预测类概率表: …

在Keras中使用深度学习得到不同的结果

我按照一个教程使用Keras中的深度神经网络进行文本分…

‘MatMul’操作的输入’b’类型为float32,与参数’a’的类型float64不匹配

我写了一个简单的TensorFlow代码,但不断遇到T…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注