借鑒上述對(duì)熵權(quán)法的介紹和實(shí)例講解撬呢,用python實(shí)現(xiàn)求解激况,主要利用的是numpy的矩陣計(jì)算投储。
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 7 11:08:54 2016
@author: debin Lu
"""
import numpy as np
import pandas as pd
fp="d:/shangquan.xlsx"
data=pd.read_excel(fp,index_col=None,header=None,encoding='utf8')
#data = (data - data.min())/(data.max() - data.min())
m,n=data.shape
#第一步讀取文件拱她,如果未標(biāo)準(zhǔn)化炸茧,則標(biāo)準(zhǔn)化
data=data.as_matrix(columns=None)
#將dataframe格式轉(zhuǎn)化為matrix格式
k=1/np.log(m)
yij=data.sum(axis=0)
pij=data/yij
#第二步瑞妇,計(jì)算pij
test=pij*np.log(pij)
test=np.nan_to_num(test)
ej=-k*(test.sum(axis=0))
#計(jì)算每種指標(biāo)的信息熵
wi=(1-ej)/np.sum(1-ej)
#計(jì)算每種指標(biāo)的權(quán)重