tf.estimator.add_metrics
| Просмотреть исходный код на GitHub |
Создаёт новый tf.estimator.Estimator с заданными метриками.
tf.estimator.add_metrics(
estimator, metric_fn
)
Пример:
def my_auc(labels, predictions):
auc_metric = tf.keras.metrics.AUC(name="my_auc")
auc_metric.update_state(y_true=labels, y_pred=predictions['logistic'])
return {'auc': auc_metric}
estimator = tf.estimator.DNNClassifier(...)
estimator = tf.estimator.add_metrics(estimator, my_auc)
estimator.train(...)
estimator.evaluate(...)
Пример использования пользовательской метрики, которая использует признаки:
def my_auc(labels, predictions, features):
auc_metric = tf.keras.metrics.AUC(name="my_auc")
auc_metric.update_state(y_true=labels, y_pred=predictions['logistic'],
sample_weight=features['weight'])
return {'auc': auc_metric}
estimator = tf.estimator.DNNClassifier(...)
estimator = tf.estimator.add_metrics(estimator, my_auc)
estimator.train(...)
estimator.evaluate(...)
| Аргументы | |
|---|---|
estimator | Объект tf.estimator.Estimator. |
metric_fn | Функция, которая должна соответствовать следующей сигнатуре:
|
| Возвращаемое значение | |
|---|---|
Новый tf.estimator.Estimator , содержащий объединение исходных метрик с заданными. |
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.3/api_docs/python/tf/estimator/add_metrics