MetricSpec connects a model to metric functions. THIS CLASS IS DEPRECATED. See [contrib/learn/README.md](https://www.tensorflow.org/code/tensorflow/contrib/learn/README.md) for general migration instructions. The MetricSpec class contains all information necessary to connect the output o
| 227 | |
| 228 | |
| 229 | class MetricSpec(object): |
| 230 | """MetricSpec connects a model to metric functions. |
| 231 | |
| 232 | THIS CLASS IS DEPRECATED. See |
| 233 | [contrib/learn/README.md](https://www.tensorflow.org/code/tensorflow/contrib/learn/README.md) |
| 234 | for general migration instructions. |
| 235 | |
| 236 | The MetricSpec class contains all information necessary to connect the |
| 237 | output of a `model_fn` to the metrics (usually, streaming metrics) that are |
| 238 | used in evaluation. |
| 239 | |
| 240 | It is passed in the `metrics` argument of `Estimator.evaluate`. The |
| 241 | `Estimator` then knows which predictions, labels, and weight to use to call a |
| 242 | given metric function. |
| 243 | |
| 244 | When building the ops to run in evaluation, an `Estimator` will call |
| 245 | `create_metric_ops`, which will connect the given `metric_fn` to the model |
| 246 | as detailed in the docstring for `create_metric_ops`, and return the metric. |
| 247 | |
| 248 | Example: |
| 249 | |
| 250 | Assuming a model has an input function which returns inputs containing |
| 251 | (among other things) a tensor with key "input_key", and a labels dictionary |
| 252 | containing "label_key". Let's assume that the `model_fn` for this model |
| 253 | returns a prediction with key "prediction_key". |
| 254 | |
| 255 | In order to compute the accuracy of the "prediction_key" prediction, we |
| 256 | would add |
| 257 | |
| 258 | ``` |
| 259 | "prediction accuracy": MetricSpec(metric_fn=prediction_accuracy_fn, |
| 260 | prediction_key="prediction_key", |
| 261 | label_key="label_key") |
| 262 | ``` |
| 263 | |
| 264 | to the metrics argument to `evaluate`. `prediction_accuracy_fn` can be either |
| 265 | a predefined function in metric_ops (e.g., `streaming_accuracy`) or a custom |
| 266 | function you define. |
| 267 | |
| 268 | If we would like the accuracy to be weighted by "input_key", we can add that |
| 269 | as the `weight_key` argument. |
| 270 | |
| 271 | ``` |
| 272 | "prediction accuracy": MetricSpec(metric_fn=prediction_accuracy_fn, |
| 273 | prediction_key="prediction_key", |
| 274 | label_key="label_key", |
| 275 | weight_key="input_key") |
| 276 | ``` |
| 277 | |
| 278 | An end-to-end example is as follows: |
| 279 | |
| 280 | ``` |
| 281 | estimator = tf.contrib.learn.Estimator(...) |
| 282 | estimator.fit(...) |
| 283 | _ = estimator.evaluate( |
| 284 | input_fn=input_fn, |
| 285 | steps=1, |
| 286 | metrics={ |
no outgoing calls