def run_experiment(pool_size, threshold, distance_method, X_train, pred_train, clf, X_test, y_test): anchors = [] for i in range(pool_size): astar = AStar(X_train.iloc[i], pred_train.iloc[i], X_train.iloc[:200], pred_train[:200], clf, threshold, list(X_train.columns), distance_method=distance_method) path = list(astar.astar(Anchor({}, list(X_train.columns)))) anchors.append((path[-1].anchor, pred_train.iloc[i])) covered = 0 precise = 0 collisions = 0 for i in range(len(X_test)): anchors_found = 0 for j in range(len(anchors)): if is_relevant(X_test.iloc[i], anchors[j][0]) and anchors_found == 0: covered += 1 anchors_found += 1 if anchors[j][1] == y_test.iloc[i]: precise += 1 if is_relevant(X_test.iloc[i], anchors[j][0]) and anchors_found == 1: collisions += 1 break precision = precise / covered coverage = covered / len(X_test) return precision, coverage