TensorFlow 神经网络的输出不变

我想制作一个基本的神经网络应用。我有一组数值。我选择一个包含30个数值的序列,并希望预测第31个数值。(希望这些数值之间存在某种关系)

我的问题是我的神经网络的输出总是1。

import tensorflow as tfINPUT_NUMBER = 30filename_queue = tf.train.string_input_producer(["googl.csv"])reader = tf.TextLineReader()key, value = reader.read(filename_queue)closeValue_ = tf.decode_csv(value, record_defaults=[[1.]])# Neural Networktf_in = tf.placeholder(tf.float32, [None, INPUT_NUMBER])tf_weight = tf.Variable(tf.random_normal([INPUT_NUMBER, 1], stddev=0.35), name="tf_weight")tf_bias = tf.Variable(tf.zeros([1]))y = tf.nn.softmax(tf.matmul(tf_in, tf_weight) + tf_bias)y_ = tf.placeholder(tf.float32, [None, 1])cost = tf.abs(tf.sub(y, y_))train_step = tf.train.AdamOptimizer().minimize(cost)init = tf.initialize_all_variables()with tf.Session() as sess:    coord = tf.train.Coordinator()    threads = tf.train.start_queue_runners(coord=coord)    data = []    for i in range(3000):        closeValue = sess.run([closeValue_])[0][0]        data.append(closeValue/10000)    sess.run(init)    for i in range(2000):        batch_xs = []        batch_ys = []        for j in range(i, i+30):            batch_xs.append(data[j])        batch_ys.append(data[j+1])        _, predictionValue, realValue = sess.run([train_step, y, y_], feed_dict={tf_in: [batch_xs], y_: [batch_ys]})        print("predictionValue: ")        print(predictionValue)        print("realValue: ")        print(realValue)    coord.request_stop()    coord.join(threads)

输出:

   predictionValue:   [[ 1.]]  realValue:   [[ 0.01313463]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01299099]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01402302]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01488589]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01502102]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01551652]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01561962]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01456456]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01558859]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01595495]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01657357]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01657758]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01712913]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01836537]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01734184]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01798599]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.0180025]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01791792]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01845596]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01649099]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01698148]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01763363]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.0178013]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01815565]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01898498]]  predictionValue:   [[ 1.]]  realValue:   [[ 0.01864565]]

回答:

您在进行回归分析,因此您的模型不应该在最后使用softmax。Softmax是一个用于生成概率估计的归一化元素,因此如果您只有一个输出,这个估计将始终是…1。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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