Orange绘制Nemenyi图时的排名倒置问题求助
问题
我用以下代码生成Nemenyi图:
import Orange import matplotlib.pyplot as plt names = ["A1","A2","A3","A4","A5","A6","A7"] avranks = [3.94,4.94,3.33,3.56,5.94,4.30,4.52] cd = Orange.evaluation.compute_CD(avranks,48,alpha="0.05") #tested on 48 datasets print("cd=",cd) Orange.evaluation.graph_ranks(avranks, names, cd=cd, width=9, textspace=1.2) plt.subplots_adjust(top=0.95, bottom=0.15, left=0.15, right=0.95) # Adjust margins as needed fig = plt.gcf() plt.rcParams.update({'font.size': 12}) # Adjust line properties after calling plot() for line in plt.gca().lines: line.set_linewidth(1.25) # Set the desired line width (e.g., 1.5) plt.show();
生成的Nemenyi图中排名越高的算法越靠左,但我的需求是排名越低的算法性能越优,希望这类算法能放在左侧。尝试使用graph_ranks的reverse参数后,虽然低排名算法(如A5)移到了左侧,但上方的排名刻度也被反转,不符合要求,寻求解决办法。
解决方法
不要使用reverse参数,而是对平均排名做反向数值转换——将每个平均排名替换为(最大排名 + 最小排名) - 当前排名,这样既能让低排名(性能优)的算法靠左,又能保持顶部的排名刻度正常递增。
修改后的代码如下:
import Orange import matplotlib.pyplot as plt names = ["A1","A2","A3","A4","A5","A6","A7"] avranks = [3.94,4.94,3.33,3.56,5.94,4.30,4.52] # 反转平均排名数值,确保排序逻辑符合需求但刻度正常 max_rank = max(avranks) min_rank = min(avranks) reversed_avranks = [(max_rank + min_rank) - r for r in avranks] cd = Orange.evaluation.compute_CD(avranks,48,alpha="0.05") # CD值仍基于原始排名计算 print("cd=",cd) # 使用转换后的排名绘图 Orange.evaluation.graph_ranks(reversed_avranks, names, cd=cd, width=9, textspace=1.2) plt.subplots_adjust(top=0.95, bottom=0.15, left=0.15, right=0.95) fig = plt.gcf() plt.rcParams.update({'font.size': 12}) for line in plt.gca().lines: line.set_linewidth(1.25) plt.show();
关键说明
- 转换后的排名会让原排名最低(性能最优)的算法变为转换后排名最高的,从而自动排列在图的左侧;
- CD值必须基于原始平均排名计算,因为它是统计检验的结果,不能跟随排名转换;
- 顶部的排名刻度会保持正常递增的显示逻辑,符合常规阅读习惯,同时算法排序满足需求。
内容的提问来源于stack exchange,提问作者rockstone435
相关产品推荐
相关产品推荐

