こんにちはすべて、Tensorflow - ニューラルネットワークは常に同じことを予測
私は特定の機能に基づいて給与を分類ニューラルネットワークを作るしようとしています。しかし、このニューラルネットのテンソルフローコードを実行すると、どのような特徴を持っていても同じことが予測されます。私はニューラルネットワークの概念などを読んでおり、私のコードは概念知識でチェックアウトしています私が間違っていることを混乱させる。私がこの分野でまだまだ無知なので、あなたが徹底的に見つけたものを説明してください。
は、これは私のコードです:
import tensorflow as tf
import numpy as np
n_inputs = 4
n_hidden1 = 2
n_hidden2 = 2
n_outputs = 1000000
X = tf.placeholder(tf.float32, shape=(None, n_inputs), name="X")
y = tf.placeholder(tf.int64, shape=(None), name="y")
with tf.name_scope("dnn"):
hidden1 = tf.layers.dense(X, n_hidden1, name="hidden1",
activation=tf.nn.relu)
hidden2 = tf.layers.dense(hidden1, n_hidden2, name="hidden2",
activation=tf.nn.relu)
logits = tf.layers.dense(hidden2, n_outputs, name="outputs")
with tf.name_scope("loss"):
xentropy = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=y, logits=logits)
loss = tf.reduce_mean(xentropy, name="loss")
learning_rate = 0.1
with tf.name_scope("train"):
optimizer = tf.train.GradientDescentOptimizer(learning_rate)
training_op = optimizer.minimize(loss)
init = tf.global_variables_initializer()
saver = tf.train.Saver()
# Training data. In every 1-D array, the first 4 elements are features and the last element is a label/output.
train_x = [[11, 3, 2, 4, 150000], [9, 2, 1, 2, 90000], [10, 4, 3, 1, 140000], [11, 3, 4, 4, 170000],
[8, 2, 1, 3, 105000], [7, 2, 1, 2, 95000], [11, 4, 2, 4, 145000], [10, 4, 1, 4, 110000],
[9, 3, 4, 4, 160000], [8, 2, 3, 4, 145000], [7, 4, 2, 4, 130000], [8, 2, 1, 2, 101000],
[10, 2, 2, 3, 130000], [10, 3, 3, 3, 140000], [8, 3, 1, 2, 105000], [7, 4, 1, 3, 95000],
[10, 3, 4, 3, 165000], [10, 3, 4, 4, 167000], [10, 4, 4, 1, 166000], [8, 4, 2, 4, 137000],
[9, 2, 2, 4, 140000], [8, 2, 2, 2, 142000], [9, 2, 2, 3, 143000], [9, 2, 2, 4, 144000], [8, 4, 2, 2, 140000],
[6, 4, 1, 4, 110000], [7, 3, 1, 2, 100000], [8, 3, 1, 3, 101000], [7, 2, 1, 3, 100000], [7, 2, 1, 3, 950000],
[7, 4, 1, 4, 980000], [8, 4, 1, 4, 100000], [8, 3, 1, 4, 100000], [9, 3, 1, 2, 101000], [8, 3, 1, 2, 107000],
[8, 3, 2, 2, 110000], [8, 2, 2, 3, 115000], [7, 4, 2, 2, 112000], [8, 2, 2, 4, 120000], [8, 4, 2, 4, 122000],
[8, 2, 2, 3, 120000], [8, 3, 2, 4, 123000], [8, 3, 2, 4, 121000], [8, 2, 2, 4, 121000], [8, 4, 2, 2, 120000]]
with tf.Session() as sess:
init.run()
#Training
for i in range(0, 45):
X_batch = [train_x[i][:4]]
y_batch = train_x[i][4:]
sess.run(training_op, feed_dict={X: X_batch, y: y_batch})
# Testing
for i in range(0, 45):
pred_data = logits.eval(feed_dict={X: [train_x[i][:4]]})
pred = np.argmax(pred_data, axis=1)
print("Predicted Value : ", pred, " Expected Value :", train_x[i][4:])
これは予測がのように見える判明するものである:
Predicted Value : [140000] Expected Value : [150000]
Predicted Value : [140000] Expected Value : [90000]
Predicted Value : [140000] Expected Value : [140000]
Predicted Value : [140000] Expected Value : [170000]
Predicted Value : [140000] Expected Value : [105000]
Predicted Value : [140000] Expected Value : [95000]
Predicted Value : [140000] Expected Value : [145000]
Predicted Value : [140000] Expected Value : [110000]
Predicted Value : [140000] Expected Value : [160000]
Predicted Value : [140000] Expected Value : [145000]
Predicted Value : [140000] Expected Value : [130000]
Predicted Value : [140000] Expected Value : [101000]
...
私は学習率などを変更、基本的な正規化を試してみました。他の投稿や質問から、しかしどこにも得ていない。
ありがとうございました。
さらにデータが必要な場合があります。少なくとも数百のサンプルのように、 – Zoe
私はそれが大好きですが、データを複製して何度も修正することでそれをテストしました。しかし、あなたの入力をありがとう! –