Keras:模型评估

博客主要围绕Keras模型评估展开,指出Keras能用的评估模型较少,部分评估在该框架下不准确,建议使用TensorFlow或Scikit-learn中的评估模型。还介绍了保存并重新导入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: 

 

 

您可能感兴趣的与本文相关的镜像

TensorFlow-v2.9

TensorFlow-v2.9

TensorFlow

TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型

评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值