Exemple #1
0
def train(player, receipt):

    learning_cfg = get_learning_cfg("conceded")
    history = train_history_utils.init_history('in progress', learning_cfg)

    training_utils.train(data_range=training_utils.create_data_range(
        learning_cfg=learning_cfg, history_file=history_file),
                         label='conceded',
                         label_values=match_dataset.CONCEDED,
                         model_dir="conceded",
                         train_path=training_utils.create_train_path(),
                         receipt=receipt,
                         history=history,
                         history_file=history_file)

    receipt_utils.put_receipt(receipt_utils.TRAIN_RECEIPT_URL, receipt, None)
def train(player, receipt):

    logger.info('started train')

    learning_cfg = get_learning_cfg("goals")

    history = train_history_utils.init_history('in progress', learning_cfg)

    training_utils.train(data_range=training_utils.create_data_range(
        learning_cfg=learning_cfg, history_file=history_file),
                         label='goals',
                         label_values=match_dataset.SCORE,
                         model_dir="goals",
                         train_path=training_utils.create_train_path(),
                         receipt=receipt,
                         history=history,
                         history_file=history_file)

    receipt_utils.put_receipt(receipt_utils.TRAIN_RECEIPT_URL, receipt, None)
def predict(data, init, label, label_values,  model_dir, receipt):

#def create(type, country, train, label, label_values, model_dir, train_filename, test_filename, outcome, previous_vocab_date):
    # there is no guarantee the predict is on same day as the train.  so we need the history
    classifier =  match_model.create(
                   train=False,
                   label=label,
                   label_values=label_values,
                   model_dir=model_dir,
                   train_filename='',
                   test_filename='',
                   init=init)

    player = []
    home = []
    opponent = []

    # Generate predictions from the model

    opponent.append(data['opponent'])
    home.append(data['home'])
    player.append(data['player'])

    predict_x = {
        'player': player,
        'opponent': opponent,
        'home': home
    }

    response = model_utils.predict(
        classifier=classifier,
        predict_x=predict_x,
        label_values=label_values)

    if init:
     logger.info('tidying up')
     match_model.tidy_up(local_dir+'/models/'+model_dir,None, None, None)

    receipt_utils.put_receipt(receipt_utils.PREDICT_RECEIPT_URL, receipt,response)
def train(data_range, label, label_values, model_dir, train_path, receipt,
          history, history_file):

    for data in data_range:

        learning_cfg = get_learning_cfg(model_dir)

        train_filename = "train-players" + data.replace('/', '-') + ".csv"
        evaluate_filename = "train-players" + get_next_in_range(
            data_range, data).replace('/', '-') + ".csv"
        train_file_path = local_dir + train_path + train_filename
        evaluate_file_path = local_dir + train_path + evaluate_filename

        has_data = model_utils.create_csv(url=model_utils.EVENT_MODEL_URL,
                                          filename=train_file_path,
                                          range=data,
                                          aws_path=train_path)

        if learning_cfg['evaluate']:

            has_test_data = model_utils.create_csv(
                url=model_utils.EVENT_MODEL_URL,
                filename=evaluate_file_path,
                range=get_next_in_range(data_range, data),
                aws_path=train_path)

            if has_data == True and has_test_data == False:
                evaluate_filename = None
            else:
                logger.info('we can evaluate')

        if has_data:

            train_filename = train_path + train_filename
            if evaluate_filename is not None:
                evaluate_filename = train_path + evaluate_filename
            ##take a copy of our file if it doesnt exist.
            #if not is_on_file(test_file_path):
            #    copyfile(train_file_path,
            #             test_file_path)
            #    put_aws_file_with_path(train_path,test_filename)
            #    write_filenames_index_from_filename(test_file_path)
            # else:
            #    get_aws_file(train_path,  test_filename)

            match_model.create(train=True,
                               label=label,
                               label_values=label_values,
                               model_dir=model_dir,
                               train_filename=train_filename,
                               test_filename=evaluate_filename,
                               init=True)
        else:
            logger.info('no data to train')

        #write the history...
        start_day, start_month, start_year, end_day, end_month, end_year = get_range_details(
            data)
        history = train_history_utils.create_history('Success - Partial',
                                                     start_day, start_month,
                                                     start_year, end_day,
                                                     end_month, end_year)
        train_history_utils.add_history(history_file, 'default', history)

    if receipt is not None:
        receipt_utils.put_receipt(receipt_utils.TRAIN_RECEIPT_URL, receipt,
                                  None)

    history['status'] = "Success - Full"
    train_history_utils.add_history(history_file, 'default', history)