示例#1
0
文件: reload.py 项目: ncanna/IRDM
    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(
        '================================================================================'
    )

    #load the model
    filename = 'models/LambdaMART_Fold_' + str(i)
    model = LambdaMART.load(filepath=filename)

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

    test_ranks = model.predict_rankings(test_queries)
    dcg_score = NDCG(test_queries, test_ranks).mean_ndcg()
    map_score = MAP(test_queries, test_ranks).mean_average_precision()
    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
示例#2
0
from rankpy.models import LambdaMART
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

with open("test.svmlight") as f:
    head = [next(f) for x in range(4)]
features = map(lambda x: x.split(':')[1], head[-1][2:-1].split(' '))
columns = pd.read_csv("../test_set_VU_DM_2014.csv", header=0,
                      nrows=1).columns.values.tolist()
lm = LambdaMART.load("LambdaMartModel0.5.model")
feats = dict(zip(features, lm.feature_importances()))
feats = sorted(feats.items(), key=lambda kv: -kv[1])

fig, ax = plt.subplots(figsize=(1200 / 120, 500 / 120))
bp = sns.barplot(map(lambda x: x[0], feats), map(lambda x: x[1], feats))

for item in bp.get_xticklabels():
    item.set_rotation(90)
plt.subplots_adjust(bottom=0.5)

plt.savefig("feature_importances", dpi=400)
from rankpy.models import LambdaMART
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

with open("test.svmlight") as f:
    head = [next(f) for x in range(4)]
features = map(lambda x: x.split(':')[1], head[-1][2:-1].split(' '))
columns = pd.read_csv("../test_set_VU_DM_2014.csv", header=0, nrows = 1).columns.values.tolist()
lm = LambdaMART.load("LambdaMartModel0.5.model")
feats = dict(zip(features, lm.feature_importances()))
feats = sorted(feats.items(), key=lambda kv: -kv[1])

fig, ax = plt.subplots(figsize=(1200/120, 500/120))
bp = sns.barplot( map(lambda x: x[0], feats), map(lambda x: x[1], feats))

for item in bp.get_xticklabels():
    item.set_rotation(90)
plt.subplots_adjust(bottom=0.5)

plt.savefig("feature_importances", dpi=400)