python - 为什么我的人工神经网络不学习?

标签 python tensorflow machine-learning neural-network

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

...

num_periods = 24
f_horizon = 48  #forecast horizon

...

#RNN designning
tf.reset_default_graph()

inputs = num_periods    #input vector size
hidden = 100    
output = num_periods    #output vector size
learning_rate = 0.01
seed = 128

x = 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 variables
epochs = 1000     #number of iterations or training cycles, includes both the FeedFoward and Backpropogation
mape = []

...

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 州的输出: cost1 cost2

我们可以看到,成本随着时代的推移不断增加。为什么会出现这种情况?

最佳答案

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

像均方误差之类的东西应该可以代替。

关于python - 为什么我的人工神经网络不学习?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51570785/

相关文章:

python - 使用 SetParent win32gui 函数将 ffplay 窗口嵌入到 tkinter 框架中

python - 使用 Pandas ExcelWriter 创建的 xlsx 文件需要修复

用于 diffstat 输出的 Python 正则表达式

tensorflow - 将 SavedModel 上传到 ML 引擎

python - 使用tensorflow_datasets.load(TF 2.1)分割训练数据以进行训练和验证

python - 视频帧作为 Tensorflow 图的输入

numpy - 将 Keras 模型的输出重新缩放回原始比例

python - 如何在 ML 分类中处理字符串数据

java - 将 Weka 模型保存到文本

python - 如何在 django 的日历应用程序中找到 "week"?