Skip to content

Commit 7f1e1a3

Browse files
Issue-1: Implement better printing of the explanations
1 parent bdbebbb commit 7f1e1a3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

mbdiff/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import click
22
from mbdiff.diff_query import DiffQuery
33
from mbdiff.diff import diff_file
4+
from mbdiff.pretty_print import present_explanations
45

56

67
@click.command()
@@ -15,8 +16,7 @@ def main(data, min_support, min_risk, max_order, query):
1516
explanations = diff_file(data, query, max_order, min_risk, min_support)
1617
print("Explanations")
1718
explanations = sorted(explanations, key=lambda x: x[0], reverse=True)
18-
for rr, combination in explanations:
19-
print(rr, combination)
19+
print(present_explanations(explanations))
2020

2121

2222
if __name__ == "__main__":

mbdiff/pretty_print.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Present explanations in a more approachable way."""
2+
from typing import List
3+
from tabulate import tabulate
4+
from pandas import DataFrame
5+
6+
7+
def present_explanations(explanations: List) -> str:
8+
pres_df = []
9+
for score, explanation in explanations:
10+
row = {"score": score}
11+
row = {**row, **explanation}
12+
pres_df.append(row)
13+
pres_df = DataFrame(pres_df)
14+
# NaN means "any value", represent as "-" just like in the original paper
15+
pres_df.fillna("-", inplace=True)
16+
return tabulate(pres_df, headers="keys")

0 commit comments

Comments
 (0)