Pros: 依据专家经验判断,相对偏主观,方便业务基于不同阶段的需求进行调整
code:
class AHP: def __init__(self, arr): self.RI = (0, 0, 0.58, 0.9, 1.12, 1.24, 1.32, 1.41, 1.45, 1.49) self.arr = np.array(arr) def cal_weight(self, arr): eig_val, eig_vector = np.linalg.eig(self.arr) self.max_val = np.max(eig_val).real ind = np.argmax(eig_val) max_vector = eig_vector[:,ind].real #ind=0 weight = max_vector / max_vector.sum() return self.max_val, weight def ck_consistency(self): n = self.arr.shape[0] CI = (self.max_val - n) / (n - 1) CR = CI / self.RI[n] return CR def run(self): max_val, weight = self.cal_weight(self.arr) CR = self.ck_consistency() print('一致性检验{}通过,准则层最大特征值为:{:.3f},CR值为:{:.3f}'.format('' if CR < 0.1 else '不', max_val, CR)) print('准则层权重为:{}'.format(weight))reference:
层次分析法原理及python实现