Estimator Eval

Use the Estimator API to evaluate the regression model.

We'll cover the following

Chapter Goals:

  • Use an Estimator object to evaluate a regression model

A. Evaluation

The Estimator object provides a function called evaluate, which is used for model evaluation.

Like the train function, evaluate also takes an input data function as its required argument. The input data function must follow the same format as the one used with train, although it can be configured differently (i.e. no shuffling, smaller batch size, etc.). We can also specify the number of steps to run evaluation for using the steps keyword argument.

The evaluate function will return a dictionary containing the final values for each evaluation metric. Each key is the name of a metric and each value is that metric’s value. The dictionary metrics consist of the model loss (corresponding to key 'loss'), as well as each metric we specified in eval_metric_ops when initializing the evaluation ExampleSpec. The dictionary will also include the final training iteration of the model, represented by 'global_step'.

Press + to interact
eval_dict = regressor.evaluate(
input_fn, # lambda function
steps=2)

Note that evaluate also creates a new eval directory inside the model checkpoint directory. In the code above, the eval directory is saved as a subdirectory within model_dir. The eval directory contains a single events file depicting the evaluation run, which can be used with TensorBoard.

Get hands-on with 1300+ tech skills courses.