mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 09:28:51 -06:00
Flip dict levels produced by PrimalSolutionComponent.evaluate
This commit is contained in:
@@ -18,6 +18,7 @@ class PrimalSolutionComponent(Component):
|
||||
"""
|
||||
A component that predicts primal solutions.
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
classifier=AdaptiveClassifier(),
|
||||
mode="exact",
|
||||
@@ -113,7 +114,8 @@ class PrimalSolutionComponent(Component):
|
||||
return solution
|
||||
|
||||
def evaluate(self, instances):
|
||||
ev = {}
|
||||
ev = {"Fix zero": {},
|
||||
"Fix one": {}}
|
||||
for instance_idx in tqdm(range(len(instances))):
|
||||
instance = instances[instance_idx]
|
||||
solution_actual = instance.solution
|
||||
@@ -146,8 +148,6 @@ class PrimalSolutionComponent(Component):
|
||||
tn_one = len(pred_one_negative & vars_zero)
|
||||
fn_one = len(pred_one_negative & vars_one)
|
||||
|
||||
ev[instance_idx] = {
|
||||
"Fix zero": classifier_evaluation_dict(tp_zero, tn_zero, fp_zero, fn_zero),
|
||||
"Fix one": classifier_evaluation_dict(tp_one, tn_one, fp_one, fn_one),
|
||||
}
|
||||
ev["Fix zero"][instance_idx] = classifier_evaluation_dict(tp_zero, tn_zero, fp_zero, fn_zero)
|
||||
ev["Fix one"][instance_idx] = classifier_evaluation_dict(tp_one, tn_one, fp_one, fn_one)
|
||||
return ev
|
||||
|
||||
@@ -50,7 +50,7 @@ def test_evaluate():
|
||||
2: 1,
|
||||
3: 1}}
|
||||
ev = comp.evaluate(instances[:1])
|
||||
assert ev == {0: {'Fix one': {'Accuracy': 0.5,
|
||||
assert ev == {'Fix one': {0: {'Accuracy': 0.5,
|
||||
'Condition negative': 1,
|
||||
'Condition negative (%)': 25.0,
|
||||
'Condition positive': 3,
|
||||
@@ -69,8 +69,8 @@ def test_evaluate():
|
||||
'True negative': 1,
|
||||
'True negative (%)': 25.0,
|
||||
'True positive': 1,
|
||||
'True positive (%)': 25.0},
|
||||
'Fix zero': {'Accuracy': 0.75,
|
||||
'True positive (%)': 25.0}},
|
||||
'Fix zero': {0: {'Accuracy': 0.75,
|
||||
'Condition negative': 3,
|
||||
'Condition negative (%)': 75.0,
|
||||
'Condition positive': 1,
|
||||
|
||||
Reference in New Issue
Block a user