2017-02-10 8 views
3

私のネットワークはすべての予測に対して同じ出力を生成します。私はパンダのデータフレームに約49,000のデータサンプルを持っています。
どうすればこの問題を解決できますか?TFLearnはすべての予測で同じ結果を生成します

# Input data X.as_matrix() => 8 dimensional array 
# One example: [1.50000000e+00,3.00000000e+00,6.00000000e+00,2.40000000e+01,9.50000000e+01,3.00000000e+03,5.00000000e+00,1.50000000e+00] 
import tensorflow as tf 
import tflearn 

with tf.Graph().as_default(): 
    net = tflearn.input_data([None, 8]) 

    net = tflearn.fully_connected(net, 20, activation='softmax',weights_init='normal',regularizer='L2', weight_decay=0.001) 
    net = tflearn.fully_connected(net, 3, activation='softmax',weights_init='normal') 
    sgd = tflearn.Adam(learning_rate=0.01) 
    net = tflearn.regression(net, optimizer=sgd,loss='categorical_crossentropy') 
    model = tflearn.DNN(net) 
    model.fit(X.as_matrix(), Y, show_metric=True, batch_size=10, n_epoch=2, snapshot_epoch=False) 
print(model.predict([X.as_matrix()[1]])) 
print(model.predict([X.as_matrix()[2]])) 
print(model.predict([X.as_matrix()[3]]))  

Result: 
[0.6711940169334412,0.24268993735313416,0.08611597120761871] 
[0.6711940169334412,0.24268993735313416,0.08611597120761871] 
[0.6711940169334412,0.24268993735313416,0.08611597120761871] 

Actual: 
[ 0, 1, 0] 
[ 1, 0, 0] 
[ 0, 0, 1] 

答えて

0

softmaxの代わりにsigmoidまたはreluを使用してください。私はそれらの2つでより良い予測を得ました。おそらく、最初のレイヤーにはシグモイドを使用し、2番目のレイヤーにはreluを使いたいかもしれません。ちょうどそれらと遊んでそれらを組み合わせるので、あなたはより良い予測を持っています。また、他の損失関数を試してみてください。

関連する問題