docs: def get_estimator(output_dir, train_config, args):
    """Returns a tf learn estimator.
  
    We only support {DNN, Linear}Regressor and {DNN, Linear}Classifier. This is
    controlled by the values of model_type in the args.
  
    Args:
      output_dir: Modes are saved into outputdir/train
      train_config: our training config
      args: command line parameters
  
    Returns:
      TF lean estimator
  
    Raises:
      ValueError: if config is wrong.
    """
  
    # Check the requested mode fits the preprocessed data.
    target_name = train_config['target_column']
    if is_classification_model(args.model_type) and target_name not in \
            train_config['categorical_columns']:
      raise ValueError('When using a classification model, the target must be a '
                       'categorical variable.')
    if is_regression_model(args.model_type) and target_name not in \
            train_config['numerical_columns']:
      raise ValueError('When using a regression model, the target must be a '
                       'numerical variable.')
  
    # Check layers used for dnn models.
    if is_dnn_model(args.model_type) and not args.layer_sizes:
      raise ValueError('--layer-size* must be used with DNN models')
    if is_linear_model(args.model_type) and args.layer_sizes:
      raise ValueError('--layer-size* cannot be used with linear models')
  
    # Build tf.learn features
    feature_columns = _tflearn_features(train_config, args)
  
    # Set how often to run checkpointing in terms of time.
    config = tf.contrib.learn.RunConfig(
        save_checkpoints_secs=args.save_checkpoints_secs)
  
    train_dir = os.path.join(output_dir, 'train')
    if args.model_type == 'dnn_regression':
      estimator = tf.contrib.learn.DNNRegressor(
          feature_columns=feature_columns,
          hidden_units=args.layer_sizes,
          config=config,
          model_dir=train_dir,
          optimizer=tf.train.AdamOptimizer(
              args.learning_rate, epsilon=args.epsilon))
    elif args.model_type == 'linear_regression':
      estimator = tf.contrib.learn.LinearRegressor(
          feature_columns=feature_columns,
          config=config,
          model_dir=train_dir,
          optimizer=tf.train.AdamOptimizer(
              args.learning_rate, epsilon=args.epsilon))
    elif args.model_type == 'dnn_classification':
      estimator = tf.contrib.learn.DNNClassifier(
          feature_columns=feature_columns,
          hidden_units=args.layer_sizes,
          n_classes=train_config['vocab_stats'][target_name]['n_classes'],
          config=config,
          model_dir=train_dir,
          optimizer=tf.train.AdamOptimizer(
              args.learning_rate, epsilon=args.epsilon))
    elif args.model_type == 'linear_classification':
      estimator = tf.contrib.learn.LinearClassifier(
          feature_columns=feature_columns,
          n_classes=train_config['vocab_stats'][target_name]['n_classes'],
          config=config,
          model_dir=train_dir,
          optimizer=tf.train.AdamOptimizer(
              args.learning_rate, epsilon=args.epsilon))
    else:
      raise ValueError('bad --model-type value')
  
    return estimator