import os import pyecharts from pyecharts.charts import Line from pyecharts import options as opts from pyecharts.charts import Bar from pyecharts.globals import ThemeType if __name__ == '__main__': outcome_dir = r'E:\Data\Research\Outcome' configs_dir = r'\Magellan+Smac+roberta-large-nli-stsb-mean-tokens+inter-0.5' datasets_list = os.listdir(outcome_dir) f1 = [] interpretability = [] for _ in datasets_list: path = outcome_dir + rf'\{_}' + configs_dir statistics_files = os.listdir(path) for i in statistics_files: if i.startswith('eval_result'): with open(path + rf'\{i}', 'r') as f: # 读取每一行的md,加入该文件的md列表 for line in f.readlines(): if line.startswith('F1'): lt = line.split(' ') value = float(lt[2].replace('%', ''))/100 f1.append(round(value, ndigits=3)) elif line.startswith('interpretability'): lt = line.split(':') value = float(lt[1]) interpretability.append(round(value, ndigits=3)) c = ( Bar() .add_xaxis( datasets_list ) .add_yaxis('F1', f1) .add_yaxis('Interpretability', interpretability) .set_global_opts( xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-15)), title_opts=opts.TitleOpts(title="各数据集F1值与预测结果可解释比例", subtitle="可解释性比重:0.5"), # yaxis_opts=opts.AxisOpts(min_=0.95) # 设置y轴起始点 ) .render("output/F1_Inter_bars.html") )