stMind

about Arsenal, Arsene Wenger, Tech, Computer vision and Machine learning

Sentiment Analysisの学習履歴をプロット

学習時のlossとaccuracyを確認するのも容易。model.fitの戻り値をhistoryとして受け取って、横軸にepoch数、縦軸にlossやaccuracyの値をとって表示するだけ。

    history = model.fit(padded, training_labels, epochs=num_epochs, validation_data=(testing_padded, testing_labels))
    acc = history.history['accuracy']
    loss = history.history['loss']
    val_acc = history.history['val_accuracy']
    val_loss = history.history['val_loss']
    epochs = range(len(acc))
    plt.plot(epochs, acc, 'r', label='acc')
    plt.plot(epochs, val_acc, 'b', label='val_acc')
    plt.plot(epochs, loss, 'r', linestyle='dashed', label='loss')
    plt.plot(epochs, val_loss, 'b', linestyle='dashed', label='val_loss')
    plt.legend()
    plt.show()

historyから取得可能な要素のリストは、keys()で確認出来る。

print(history.history.keys())

# this might produces the following
# dict_keys(['loss', 'accuracy', 'val_loss', 'val_accuracy'])

f:id:satojkovic:20200620125738p:plain