Esempio n. 1
0
def trainModel(training_set, out, features=None, kcv=None, ranker=6,
               leafs=10, trees=50, frate=1.0, shrinkage=0.1,
               srate=1.0, bag=1, metric2t='DCG@10'):
    """
    ranker
    - 6 for LambdaMART
    - 8 for RandomForest

    RandomForest params
        frate - what proportion of features are candidates at each split
        srate - what proportion of the queries should be examined for each ensemble
    """

    ranky_loc = check_for_rankymcrankface()
    training_set_path = write_training_set(training_set)
    cmd = 'java -jar {} -ranker {} -shrinkage {} -metric2t {} -tree {} -bag {} -leaf {} -frate {} -srate {} -train {} -save {} '.format(
            ranky_loc, ranker, shrinkage, metric2t, trees, bag, leafs, frate, srate, training_set_path, out)

    if features is not None:
        import tempfile
        features_file = os.path.join(tempfile.gettempdir(),'features.txt')
        with open(features_file, 'w') as f:
            f.write("\n".join([str(feature) for feature in features]))
        cmd += " -feature {}".format(features_file)

    if kcv is not None and kcv > 0:
        cmd += " -kcv {} ".format(kcv)

    print("Running %s" % cmd)
    result = os.popen(cmd).read()
    print("DONE")
    return parse_training_log(result)
Esempio n. 2
0
def trainModel(training,
               out,
               features=None,
               kcv=None,
               ranker=6,
               leafs=10,
               trees=50,
               frate=1.0,
               shrinkage=0.1,
               srate=1.0,
               bag=1,
               metric2t='DCG@10'):
    """
    ranker
    - 6 for LambdaMART
    - 8 for RandomForest

    RandomForest params
        frate - what proportion of features are candidates at each split
        srate - what proportion of the queries should be examined for each ensemble
    """

    cmd = 'java -jar data/RankyMcRankFace.jar -ranker {} -shrinkage {} -metric2t {} -tree {} -bag {} -leaf {} -frate {} -srate {} -train {} -save {} '.format(
        ranker, shrinkage, metric2t, trees, bag, leafs, frate, srate, training,
        out)

    if features is not None:
        with open('features.txt', 'w') as f:
            f.write("\n".join([str(feature) for feature in features]))
        cmd += " -feature features.txt "

    if kcv is not None and kcv > 0:
        cmd += " -kcv {} ".format(kcv)

    print("Running %s" % cmd)
    result = os.popen(cmd).read()
    print("DONE")
    return parse_training_log(result)
Esempio n. 3
0
def trainModel(training,
               out,
               features=None,
               kcv=None,
               leafs=10,
               trees=10,
               metric2t='DCG@10'):

    cmd = 'java -jar data/RankyMcRankFace.jar -ranker 6 -metric2t {} -tree {} -leaf {} -train {} -save {} '.format(
        metric2t, leafs, trees, training, out)

    if features is not None:
        with open('features.txt', 'w') as f:
            f.write("\n".join([str(feature) for feature in features]))
        cmd += " -feature features.txt "

    if kcv is not None and kcv > 0:
        cmd += " -kcv {} ".format(kcv)

    print("Running %s" % cmd)
    result = os.popen(cmd).read()
    print("DONE")
    return parse_training_log(result)