code: def train_and_evaluate(
      working_dir,
      num_train_instances=common.NUM_TRAIN_INSTANCES,
      num_test_instances=common.NUM_TEST_INSTANCES,
  ):
      """Train the model on training data and evaluate on test data.
  
      Args:
        working_dir: Directory to read transformed data and metadata from and to
            write exported model to.
        num_train_instances: Number of instances in train set
        num_test_instances: Number of instances in test set
  
      Returns:
        The results from the estimator's 'evaluate' method
      """
      tf_transform_output = tft.TFTransformOutput(working_dir)
  
      run_config = tf_estimator.RunConfig()
  
      estimator = tf_estimator.LinearClassifier(
          feature_columns=get_feature_columns(tf_transform_output),
          config=run_config,
          loss_reduction=tf.losses.Reduction.SUM,
      )
  
      # Fit the model using the default optimizer.
      train_input_fn = _make_training_input_fn(
          tf_transform_output,
          os.path.join(
              working_dir, common.TRANSFORMED_TRAIN_DATA_FILEBASE + "*"
          ),
          batch_size=common.TRAIN_BATCH_SIZE,
      )
      estimator.train(
          input_fn=train_input_fn,
          max_steps=common.TRAIN_NUM_EPOCHS
          * num_train_instances
          / common.TRAIN_BATCH_SIZE,
      )
  
      # Evaluate model on test dataset.
      eval_input_fn = _make_training_input_fn(
          tf_transform_output,
          os.path.join(
              working_dir, common.TRANSFORMED_TEST_DATA_FILEBASE + "*"
          ),
          batch_size=1,
      )
  
      # Export the model.
      serving_input_fn = _make_serving_input_fn(tf_transform_output)
      exported_model_dir = os.path.join(
          working_dir, common.EXPORTED_MODEL_DIR
      )
      estimator.export_saved_model(exported_model_dir, serving_input_fn)
  
      return estimator.evaluate(
          input_fn=eval_input_fn, steps=num_test_instances
      )
  
file_path: transform/examples/census_example.py
imports: import os
  import pprint
  import tempfile
  import tensorflow
  from tensorflow import estimator
  import tensorflow_transform
  import census_example_common
label_desc: Use image node_id 5 for calling a global function with example usage: train_and_evaluate(working_dir, num_train_instances, num_test_instances) and returns: estimator