正在打开模型库
正在打开模型库
TOPSIS 用于评价多个方案哪个更接近理想方案。
先想象最好和最差两个虚拟方案,看每个真实方案离它们有多远,越靠近最好、远离最差越好。
题目出现“评价、排序、综合水平、方案比选”时,它通常是第一候选。
Python 代码
import numpy as np
# 示例:4 个城市,3 个指标(越大越好)
X = np.array([
[80, 70, 90],
[75, 85, 70],
[90, 65, 80],
[70, 90, 75],
], dtype=float)
# 标准化
norm = X / np.sqrt((X ** 2).sum(axis=0))
# 熵权可替换这里的权重
w = np.array([0.4, 0.3, 0.3])
V = norm * w
ideal = V.max(axis=0)
nadir = V.min(axis=0)
d_pos = np.sqrt(((V - ideal) ** 2).sum(axis=1))
d_neg = np.sqrt(((V - nadir) ** 2).sum(axis=1))
score = d_neg / (d_pos + d_neg)
rank = score.argsort()[::-1] + 1
print("贴近度:", np.round(score, 4))
print("排名:", rank)