コード例 #1
0
logging.info(
    '================================================================================'
)

model = LambdaMART(
    metric='NDCG@10',
    max_leaf_nodes=7,
    shrinkage=0.1,
    estopping=30,
    n_jobs=-1,
    random_state=42,
    use_pines=True,
    pines_kwargs=dict(
        switch_criterion=ObliviousCartSwitchCriterionType.OBLIVIOUS_WHILE_CAN,
        tree_type=TreeType.OBLIVIOUS_CART,
        max_n_splits=10,
        min_samples_leaf=50,
        max_depth=10,
    ))

model.fit(training_queries, validation_queries=validation_queries)

logging.info(
    '================================================================================'
)

logging.info('%s on the test queries: %.8f' %
             (model.metric, model.evaluate(test_queries, n_jobs=-1)))

model.save('LambdaMART_L7_S0.1_E50_' + model.metric)
コード例 #2
0
    dcg_folds_scores.append(dcg_score)
    map_folds_scores.append(map_score)

    #evaluate nDCG10 on test queries for best model
    logging.info('%s on the test queries: %.8f' % ('NDCG@10', dcg_score))

    #evaluate MAP on test queries
    logging.info('%s on the test queries: %.8f' % ('MAP', map_score))

    with open('folds_results.txt', 'a') as f:
        f.write("Fold %d \n" % (i))
        f.write("nDCG@10 %f\n" % (dcg_score))
        f.write("MAP %f\n" % (map_score))

    #save the model
    model.save('models/LambdaMART_Fold_' + str(i))
    # filename = 'models/LambdaMART_L7_S0.1_E50_nDCG@10'
    # model = LambdaMART.load(filepath=filename)

#average the ndcgs and the maps
dcg_mean = np.mean(dcg_folds_scores)
#evaluate nDCG10 on test queries for best model
logging.info('Average %s on the test queries from all folds: %.8f' %
             ('NDCG@10', dcg_mean))

map_mean = np.mean(map_folds_scores)
#evaluate MAP on test queries
logging.info('Average %s on the test queries from all folds: %.8f' %
             ('MAP', map_mean))

with open('folds_results.txt', 'a') as f:
コード例 #3
0
ファイル: lambdamart_example.py プロジェクト: dmitru/rankpy
# Find constant query-document features.
cfs = find_constant_features([training_queries,
                              validation_queries,
                              test_queries])

# Get rid of constant features and (possibly) remove useless queries.
training_queries.adjust(remove_features=cfs, purge=remove_useless_queries)
validation_queries.adjust(remove_features=cfs, purge=remove_useless_queries)
test_queries.adjust(remove_features=cfs)

# Print basic info about query datasets.
logging.info('Train queries: %s' % training_queries)
logging.info('Valid queries: %s' % validation_queries)
logging.info('Test queries: %s' % test_queries)

logging.info('=' * 80)

model = LambdaMART(metric='NDCG@10', max_leaf_nodes=7, shrinkage=0.1,
                   estopping=50, n_jobs=-1, min_samples_leaf=50,
                   random_state=42)

model.fit(training_queries, validation_queries=validation_queries)

logging.info('=' * 80)

logging.info('%s on the test queries: %.8f'
             % (model.metric, model.evaluate(test_queries, n_jobs=-1)))

model.save('LambdaMART_L7_S0.1_E50_' + model.metric)