# -*- encoding=utf-8 -*-
import warnings
import xlrd
warnings.filterwarnings("ignore")
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import csv
def get_score(wi_list,data):
"""
:param wi_list: 权重系数列表
:param data:评价指标数据框
:return:返回得分
"""
# 将权重转换为矩阵
cof_var = np.mat(wi_list)
# 将数据框转换为矩阵
context_train_data = np.mat(data)
# 权重跟自变量相乘
last_hot_matrix = context_train_data * cof_var.T
last_hot_matrix = pd.DataFrame(last_hot_matrix)
# 累加求和得到总分
last_hot_score = list(last_hot_matrix.apply(sum))
# max-min 归一化
# last_hot_score_autoNorm = autoNorm(last_hot_score)
# 值映射成分数(0-100分)
# last_hot_score_result = [i * 100 for i in last_hot_score_autoNorm]
return last_hot_score
def get_entropy_weight(data):
"""
:param data: 评价指标数据框
:return: 各指标权重列表
"""
# 数据标准化
data = (data - data.min())/(data.max() - data.min())
m,n=data.shape
#将dataframe格式转化为matrix格式
data=data.values
k=1/np.log(m)
yij=data.sum(axis=0)
#第二步,计算pij
pij=data/yij
test=pij*np.log(pij)
test=np.nan_to_num(test)
#计算每种指标的信息熵
ej=-k*(test.sum(axis=0))
#计算每种指标的权重
wi=(1-ej)/np.sum(1-ej)
wi_list=list(wi)
return wi_list
if __name__ == '__main__':
data0 = pd.read_excel("C:\\Users\\保乐\\Desktop\\数据.xlsx")
data = data0.iloc[:, 1:15]*3
mm=data
wi_list=get_entropy_weight(data)
score_list=get_score(mm,wi_list)
mm['score']=score_list
mm['case']=data0['case']
# 然后对数据框按得分从大到小排序
result = mm.sort_values(by='score', axis=0, ascending=False)
result['rank'] = range(1, len(result) + 1)
print(result)
print(wi_list)
# 写出csv数据
result.to_csv('C:\\Users\\保乐\\Desktop\\数据11.csv', index=False)
file = open('C:\\Users\\保乐\\Desktop\\数据11.csv')
reader = csv.reader(file)
original = list(reader)
file1 = open('C:\\Users\\保乐\\Desktop\\数据11.csv', "w", newline="")
content = csv.writer(file1)
for row in original:
content.writerow(row)
content.writerow(wi_list)
file.close()
file1.close()
dataLenth = len(result)
result1 = result.values
cases = result['case']
# scores = result['score']*100
scores = []
for i in range(dataLenth):
scores.append(result1[i][11] * 100)
scores.append(result1[0][11] * 100)
angles = np.linspace(0, 2 * np.pi, dataLenth, endpoint=False)
# data = np.concatenate((scores, scores[0])) # 闭合 # #将数据结合起来
angles = np.concatenate((angles, [angles[0]])) # 闭合
fig = plt.figure()
ax = fig.add_subplot(121, polar=True) # polar参数!!代表画圆形!!!!
# 111代表总行数总列数位置
ax.plot(angles, scores, 'bo-', linewidth=1) # 画线四个参数为x,y,标记和颜色,闲的宽度
ax.fill(angles, scores, facecolor='r', alpha=0.1) # 填充颜色和透明度
ax.set_thetagrids(np.unique(angles) * 180 / np.pi, cases, fontproperties="SimHei")
ax.set_title("属性分析", va='baseline', fontproperties="SimHei")
ax.set_rlim(0, 100)
ax.grid(True)
plt.show()
能效评估程序_能效_能效评估_雷达_评估_源码
版权申诉
5星 · 超过95%的资源 118 浏览量
2021-10-04
01:06:38
上传
评论
收藏 10KB RAR 举报
呼啸庄主
- 粉丝: 74
- 资源: 4702
最新资源
- FloEFD 2021版案例教程-03 多孔介质
- 一款极好用的 Office/WPS/Word/Excel/PPT/PDF工具箱软件 OfficeUtils 3.1
- FloEFD 2021版案例教程-02 共轭传热
- java毕业设计+扫雷(程序)
- 一款极好用的 Office/WPS/Word/Excel/PPT/PDF工具箱软件 OfficeUtils 2.8
- 轻松学51单片机-基于普中科技开发板练习蓝桥杯及机器人大赛等(6-蜂鸣器)
- strawberry-perl-5.38.2.2-64bit.msi
- FloEFD 2021版案例教程-01 球阀设计
- MeyboMail Web(Java)简化版
- java(结合lucene)版的公交搜索系统
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论1