Esempio n. 1
0
def train(pipeline,
          output_dir,
          train_args_dict,
          train_features=None,
          eval_features=None,
          metadata=None):
    if not train_features:
        train_features = (pipeline
                          | 'ReadTrain' >> io.LoadFeatures(
                              os.path.join(output_dir, 'features_train*')))
    if not eval_features:
        eval_features = (pipeline
                         | 'ReadEval' >> io.LoadFeatures(
                             os.path.join(output_dir, 'features_eval*')))
    if not metadata:
        metadata = (pipeline
                    | 'ReadMetadata' >> io.LoadMetadata(
                        os.path.join(output_dir, METADATA_FILE_NAME)))

    trained_model, results = ((train_features, eval_features)
                              | 'Train' >> ml.Train(**train_args_dict))

    trained_model | 'SaveModel' >> io.SaveModel(
        os.path.join(output_dir, 'saved_model'))
    results | io.SaveTrainingJobResult(
        os.path.join(output_dir, 'train_results'))

    return trained_model, results
Esempio n. 2
0
def train(pipeline, train_features=None, eval_features=None, metadata=None):
  if not train_features:
    train_features = (
        pipeline
        | 'ReadTrain'
        >> io.LoadFeatures(os.path.join(args.output_dir, 'features_train*')))
  if not eval_features:
    eval_features = (
        pipeline
        | 'ReadEval'
        >> io.LoadFeatures(os.path.join(args.output_dir, 'features_eval*')))

  trained_model, results = ((train_features, eval_features)
                            | ml.Train(**get_train_parameters(metadata)))

  trained_model | 'SaveModel' >> io.SaveModel(os.path.join(args.output_dir,
                                                           'saved_model'))
  results | io.SaveTrainingJobResult(os.path.join(args.output_dir,
                                                  'train_results'))

  return trained_model, results