Ejemplo n.º 1
0
def test(baseline_file, data_set):
    assert baseline_file is not None, "Must give model to test"
    trees = load_trees(data_set)
    assert trees, "No data found"
    with open(baseline_file, 'rb') as fid:
        opts = pickle.load(fid)
        baseline = Baseline(opts.output_dim)
        baseline.from_file(fid)
    print("Testing...")
    correct, total, pred = baseline.predict(trees)
    print("Correct %d/%d, Acc %f" % (correct, total, correct / float(total)))

    print_trees('results/gold.txt', trees, 'Labeled')
    print_trees('results/pred_baseline.txt', pred, 'Baseline predicted')
Ejemplo n.º 2
0
def test(baseline_file, data_set):
    assert baseline_file is not None, "Must give model to test"
    trees = load_trees(data_set)
    assert trees, "No data found"
    with open(baseline_file, 'rb') as fid:
        opts = pickle.load(fid)
        baseline = Baseline(opts.output_dim)
        baseline.from_file(fid)
    print("Testing...")
    correct, total, pred = baseline.predict(trees)
    print("Correct %d/%d, Acc %f" % (correct, total, correct / float(total)))

    print_trees('results/gold.txt', trees, 'Labeled')
    print_trees('results/pred_baseline.txt', pred, 'Baseline predicted')
Ejemplo n.º 3
0
from recsys.evaluation.prediction import RMSE, MAE
from recsys.datamodel.data import Data

from baseline import Baseline #Import the test class we've just created

#Dataset
PERCENT_TRAIN = int(sys.argv[2])
data = Data()
data.load(sys.argv[1], sep='::', format={'col':0, 'row':1, 'value':2, 'ids': int})
#Train & Test data
train, test = data.split_train_test(percent=PERCENT_TRAIN)

baseline = Baseline()
baseline.set_data(train)
baseline.compute() # In this case, it does nothing

# Evaluate
rmse = RMSE()
mae = MAE()
for rating, item_id, user_id in test.get():
    try:
        pred_rating = baseline.predict(item_id, user_id, user_is_row=False)
        rmse.add(rating, pred_rating)
        mae.add(rating, pred_rating)
    except KeyError:
        continue

print 'RMSE=%s' % rmse.compute() # in my case (~80% train, ~20% test set) returns RMSE = 1.036374
print 'MAE=%s' % mae.compute()   # in my case (~80% train, ~20% test set) returns  MAE = 0.829024
Ejemplo n.º 4
0
data.load(sys.argv[1],
          sep='::',
          format={
              'col': 0,
              'row': 1,
              'value': 2,
              'ids': int
          })
#Train & Test data
train, test = data.split_train_test(percent=PERCENT_TRAIN)

baseline = Baseline()
baseline.set_data(train)
baseline.compute()  # In this case, it does nothing

# Evaluate
rmse = RMSE()
mae = MAE()
for rating, item_id, user_id in test.get():
    try:
        pred_rating = baseline.predict(item_id, user_id, user_is_row=False)
        rmse.add(rating, pred_rating)
        mae.add(rating, pred_rating)
    except KeyError:
        continue

print 'RMSE=%s' % rmse.compute(
)  # in my case (~80% train, ~20% test set) returns RMSE = 1.036374
print 'MAE=%s' % mae.compute(
)  # in my case (~80% train, ~20% test set) returns  MAE = 0.829024