Exemplo n.º 1
0
submit_predict = model.predict(X_test, batch_size=batch_size).reshape(
    (1, len(X_test)))[0]

pickle.dump((test, submit_predict), open("./tmp/submit_cnn_lstm.p", 'wb'))
exit()
print("Saving model and weights...")
json_string = model.to_json()
open('./tmp/keras_model_architecture.json', 'w').write(json_string)
model.save_weights('./tmp/keras_model_weights.h5', overwrite=True)
print("Model saved.")

from metrics import continuous_metrics

continuous_metrics(Y_test, predict, 'prediction result:')

# visualization
from visualize import draw_linear_regression

X = range(50, 100)  # or range(len(y_test))
draw_linear_regression(X,
                       np.array(Y_test)[X],
                       np.array(predict)[X], 'Sentence Number',
                       "Sentiment scores",
                       'Comparison of predicted and true scores')

from visualize import plot_keras, draw_hist

plot_keras(result, x_labels='Epoch', y_labels='MAE Loss')
draw_hist(np.array(Y_test) - np.array(predict),
          title='Histogram of sentiment scores prediction: ')
Exemplo n.º 2
0
# experiment evaluated by multiple metrics
predict = model.predict(X_test, batch_size=batch_size).reshape((1, len(X_test)))[0]
print('Y_test: %s' % str(Y_test))
print('Predict value: %s' % str(predict))

submit_predict = model.predict(X_test, batch_size=batch_size).reshape((1, len(X_test)))[0]

pickle.dump((test, submit_predict), open("./tmp/submit_cnn_lstm.p", 'wb'))
exit()
print("Saving model and weights...")
json_string = model.to_json()
open('./tmp/keras_model_architecture.json', 'w').write(json_string)
model.save_weights('./tmp/keras_model_weights.h5', overwrite=True)
print("Model saved.")

from metrics import continuous_metrics

continuous_metrics(Y_test, predict, 'prediction result:')

# visualization
from visualize import draw_linear_regression

X = range(50, 100)  # or range(len(y_test))
draw_linear_regression(X, np.array(Y_test)[X], np.array(predict)[X], 'Sentence Number', "Sentiment scores",
                       'Comparison of predicted and true scores')

from visualize import plot_keras, draw_hist

plot_keras(result, x_labels='Epoch', y_labels='MAE Loss')
draw_hist(np.array(Y_test) - np.array(predict), title='Histogram of sentiment scores prediction: ')
Exemplo n.º 3
0
    early_stopping = EarlyStopping(monitor='val_loss', patience=5)
    result = model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=50, validation_data=(X_test, y_test),
              callbacks=[early_stopping])
    score = model.evaluate(X_test, y_test, batch_size=batch_size)
    print('Test score:', score)

    # experiment evaluated by multiple metrics
    predict = model.predict(X_test, batch_size=batch_size).reshape((1, len(X_test)))[0]
    print('Y_test: %s' %str(y_test))
    print('Predict value: %s' % str(predict))

    '''
    predict = np.array([5] * len(y_test))
    from metrics import continuous_metrics
    continuous_metrics(y_test, predict, 'prediction result:')

    # visualization
    from visualize import draw_linear_regression

    X = range(50, 100)  # or range(len(y_test))
    draw_linear_regression(X,
                           np.array(y_test)[X],
                           np.array(predict)[X], 'Sentence Number', option,
                           'Comparison of predicted and true ' + option)

    from visualize import plot_keras, draw_hist

    # plot_keras(result, x_labels='Epoch', y_labels='Loss')
    draw_hist(np.array(y_test) - np.array(predict),
              title='Histogram of ' + option + ' prediction: ')
Exemplo n.º 4
0
    model.compile(loss='mse', optimizer='adagrad')  # loss function: mse

    print("Train...")
    early_stopping = EarlyStopping(monitor='val_loss', patience=5)
    result = model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=50, validation_data=(X_test, y_test),
              callbacks=[early_stopping])
    score = model.evaluate(X_test, y_test, batch_size=batch_size)
    print('Test score:', score)

    # experiment evaluated by multiple metrics
    predict = model.predict(X_test, batch_size=batch_size).reshape((1, len(X_test)))[0]
    print('Y_test: %s' %str(y_test))
    print('Predict value: %s' % str(predict))

    '''
    predict = np.array([5] * len(y_test))
    from metrics import continuous_metrics
    continuous_metrics(y_test, predict, 'prediction result:')

    # visualization
    from visualize import draw_linear_regression

    X = range(50, 100)  # or range(len(y_test))
    draw_linear_regression(X, np.array(y_test)[X], np.array(predict)[X], 'Sentence Number', option,
                           'Comparison of predicted and true ' + option)

    from visualize import plot_keras, draw_hist

    # plot_keras(result, x_labels='Epoch', y_labels='Loss')
    draw_hist(np.array(y_test) - np.array(predict), title='Histogram of ' + option + ' prediction: ')