示例#1
0
def mds_and_plot(model):

    data = DataSet()
    x, y, data_list = data.get_test_frames('train')

    custom_model = Model(inputs=model.input,
                         outputs=model.get_layer('dense_1').output)
    y_pred = custom_model.predict(x)
    mds = MDS()
    mds.fit(y_pred)
    a = mds.embedding_

    mark = ['or', 'ob', 'og', 'oy', 'ok', '+r', 'sr', 'dr', '<r', 'pr']
    color = 0
    j = 0
    for item in y:
        index = 0
        for i in item:
            if i == 1:
                break
            index = index + 1

        plt.plot([a[j:j + 1, 0]], [a[j:j + 1, 1]], mark[index], markersize=5)
        print(index)
        j += 1
    plt.show()
def test_rnn(src, model):
    data = DataSet(src)
    x, y, data_list = data.get_test_frames('train')
    s = time.clock()
    y_pred = model.predict(x)
    e = time.clock()
    print(e - s)
    y_pred[y_pred < 0.7] = 0
    y_pred[y_pred >= 0.7] = 1

    print(metrics.precision_score(y, y_pred, average='micro', zero_division=0))
    print(metrics.precision_score(y, y_pred, average='macro', zero_division=0))
    print(metrics.recall_score(y, y_pred, average='micro', zero_division=0))
    print(metrics.recall_score(y, y_pred, average='macro', zero_division=0))
    print(metrics.f1_score(y, y_pred, average='weighted', zero_division=0))