| import matplotlib.pyplot as plt |
| import pandas as pd |
| import os |
| import argparse |
| import json |
| import numpy as np |
| from matplotlib.patches import Patch |
|
|
| split = os.getenv('split', '') |
| suf_split = f'-{split}' if split else '' |
|
|
| RESULT_DIR = f'./results{suf_split}' |
| cat_apps_file = f'./cat_apps{suf_split}.json' |
|
|
|
|
| def plot_box(random_data, guided_data, datatype, min_apps = 0): |
| DATATYPE_MAP = { |
| 'effective_interacts_cnt': 'Effective Interacts Count', |
| 'effective_interacts_rate': 'Effective Interacts Rate', |
| 'coverage_rate': 'IGE Coverage Rate' |
| } |
|
|
| |
| with open(cat_apps_file, 'r') as f: |
| category_apps_map = json.load(f) |
| categories = [cat for cat, apps in category_apps_map.items() if len(apps) >= min_apps and cat != 'All'] |
| categories = ['All'] + categories |
| |
| |
| |
|
|
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
|
|
| |
| |
|
|
| base, ori = {}, {} |
| for i, category in enumerate(categories): |
| base[category] = random_data[category].dropna().tolist() |
| ori[category] = guided_data[category].dropna().tolist() |
|
|
| positions = np.arange(len(categories)) |
| width = 0.35 |
|
|
| dataA = [base[c] for c in categories] |
| dataB = [ori[c] for c in categories] |
|
|
| |
| fig, ax = plt.subplots(figsize=(15, 5)) |
| box_base = ax.boxplot(dataA, positions=positions - width/2, widths=0.3, vert=False, patch_artist=True) |
| for box in box_base['boxes']: |
| box.set(facecolor="purple", alpha=0.7) |
|
|
| box_ori = ax.boxplot(dataB, positions=positions + width/2, widths=0.3, vert=False, patch_artist=True) |
| for box in box_ori['boxes']: |
| box.set(facecolor="blue", alpha=0.7) |
|
|
| for y in positions[:-1]: |
| ax.axhline( |
| y + 0.5, |
| linestyle="--", |
| linewidth=0.8, |
| alpha=0.5, |
| color="gray" |
| ) |
|
|
| |
| ax.set_yticks(positions) |
| ax.set_yticklabels(categories, fontsize=16) |
| ax.set_xlabel("Value") |
| ax.set_ylabel("App Category") |
| |
| ax.legend( |
| handles=[ |
| Patch(facecolor='blue', alpha=0.7, label='Orienter'), |
| Patch(facecolor='purple', alpha=0.7, label='Baseline') |
| ] |
| ) |
|
|
| fig.tight_layout(rect=[0.02, 0.02, 1, 1]) |
| fig.savefig(f'{RESULT_DIR}/category_eval_{datatype}.png', format='png') |
| fig.savefig(f'{RESULT_DIR}/category_eval_{datatype}.pdf', format='pdf') |
|
|
|
|
|
|
| def main(args): |
| random_data = pd.read_csv(f'{args.random}/{args.type}.csv') |
| guided_data = pd.read_csv(f'{args.guided}/{args.type}.csv') |
|
|
| plot_box(random_data, guided_data, args.type, min_apps=args.min_apps) |
|
|
|
|
| if __name__ == '__main__': |
| parser = argparse.ArgumentParser(description='Plot the category evaluation results') |
| parser.add_argument('-r', '--random', type=str, help='The random interact evaluation result') |
| parser.add_argument('-g', '--guided', type=str, help='The our interact evaluation result') |
| parser.add_argument('-t', '--type', type=str, help='The type of the evaluation result') |
| parser.add_argument('-m', '--min_apps', type=int, default=1, help='Minimum number of apps per category') |
| args = parser.parse_args() |
| main(args) |
|
|