Keras:模型評估

 

keras模型評估

keras能用的模型評估不多,有的可能是這些評估在keras框架下不準確,如果要用,可以使用tensorflow或者sklearn中的評估模型。

tensorflow:

from tensorflow.python.estimator import training

result = training.train_and_evaluate(dnn_estimator, train_spec, eval_spec)
print(result[:10])
# ({'accuracy': 0.8025, 'accuracy_baseline': 0.5, 'auc': 0.89911944, 'auc_precision_recall': 0.8918648, 'average_loss': 0.40619093, 'label/mean': 0.5, 'loss': 51.85416, 'precision': 0.7941653, 'prediction/mean': 0.5040493, 'recall': 0.81666666, 'global_step': 92450}, [])

sklearn:

from sklearn import metrics

test_pred_prob_y = model.predict(test_x, batch_size=batch_size)
print(metrics.roc_auc_score(np.argmax(test_y, axis=1), np.argmax(test_pred_prob_y, axis=1)))

 

保存keras模型並重新導入,發現自己定義的損失函數/評估指標不能用?

1 加一個custom_objects

model = load_model('***.h5',custom_objects={'my_loss': my_loss, 'my_metrics':my_metrics})

def auc(y_true, y_pred):
    auc = tf.metrics.auc(y_true, y_pred)[1]
    backend.get_session().run(tf.local_variables_initializer())
    return auc

model.save(model_file)
model = models.load_model(model_file, custom_objects={'auc': auc})

2 或者也可以把自定義的loss拷貝到keras.losses.py 源代碼文件下

[Scikit-learn:模型評估Model evaluation]

from: -柚子皮-

ref: 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章