-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluate.py
26 lines (21 loc) · 998 Bytes
/
evaluate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from problog.ddnnf_formula import DDNNF
from problog.formula import LogicFormula
from problog.program import PrologString
from utility import read_mapping
from sklearn import metrics
def predict_edge(path, user):
with open(f"{path}/learn.pl", "r") as file:
program = file.read()
targets = read_mapping(f"{path}/test.txt")
with open(f"{path}/predict.txt", "w") as file:
for movie in targets.keys():
prediction = list(DDNNF.create_from(LogicFormula.create_from(
PrologString(program + f"\nquery(watched({user},{movie}))."))).evaluate().values())[0]
file.write(f"{movie}:{prediction}\n")
def evaluate(path):
targets = read_mapping(f"{path}/test.txt")
predictions = read_mapping(f"{path}/predict.txt")
points = list(targets.keys())
targets = [float(targets[point][0]) for point in points]
predictions = [float(predictions[point][0]) for point in points]
return metrics.roc_auc_score(targets, predictions)