使用lstm减少keras训练中的损失

时间:2017-08-23 09:13:09

标签: machine-learning keras lstm training-data

我有这样的输入:

x_train = [
    [0,0,0,1,-1,-1,1,0,1,0,...,0,1,-1],
    [-1,0,0,-1,-1,0,1,1,1,...,-1,-1,0],
    ...
    [1,0,0,1,1,0,-1,-1,-1,...,-1,-1,0]
]

其中1表示一个指标增加,-1表示减少,0表示指标没有变化。每个数组有83个项目,83个字段,每个数组的输出(标签)是一个分类数组,显示这些指标对单个指标的影响:

[[ 0.  0.  1.]
 [ 1.  0.  0.],
 [ 0.  0.  1.],
 ...
 [ 0.  0.  1.],
 [ 1.  0.  0.]]

我在以下代码中使用了keraslstm

def train(x, y, x_test, y_test):
    x_train = np.array(x)
    y_train = np.array(y)
    y_train = to_categorical(y_train, 3)
    model = Sequential()
    model.add(Embedding(x_train.shape[0], output_dim=256))
    model.add(LSTM(128))
    model.add(Dropout(0.5))
    model.add(Dense(3, activation='softmax'))
    opt = optimizers.SGD(lr=0.001)
    model.compile(loss='categorical_crossentropy',
            optimizer=opt,
            metrics=['accuracy'])
    model.fit(x_train, y_train, batch_size=128, nb_epoch=100)
    y_test = to_categorical(y_test, 3)
    score = model.evaluate(x_test, y_test, batch_size=128)
    prediction = model.predict(x_test, batch_size=128)
    print score
    print prediction

但是100个时期之后的损失是:

1618/1618 [==============================] - 0s - loss: 0.7328 - acc: 0.5556

如何降低此损失百分比?

0 个答案:

没有答案