import pandas as pd
from pandas import DataFrame
import numpy as np
import math
dates=pd.read_csv(r"C:\Users\相关数据.csv",encoding='gbk')
dates.head()
PH_list=[]
for i in range(0,len(dates)):
PH_list.append(abs(dates.iloc[i]['PH值']-7))
M2=max(PH_list)
PH值_sorted=[]
for i in range(0,len(dates)):
PH值_sorted.append(1-abs(dates.iloc[i]['PH值']-7)/M2)
细菌总数越小越好,即极小型转化为极大型(max-x)
bac_sorted=[]
M3=dates['细菌总数'].max()
for i in range(0,len(dates)):
bac_sorted.append(M3-dates.iloc[i]['细菌总数'])
植物性营养物介于10-20之间最佳,即区间型指标转换为极大型指标
a=10
b=20
M4_list=[]
a_lists=dates['植物性营养物量']<a
b_lists=dates['植物性营养物量']>b
for i in range(0,len(a_lists)):
if(a_lists.loc[i]==True):
M4_list.append(a-dates.iloc[i]['植物性营养物量'])
elif(b_lists.loc[i]==True):
M4_list.append(dates.iloc[i]['植物性营养物量']-b)
M4=max(M4_list)
sub_sorted=[]
for i in range(0,len(dates)):
if(dates.iloc[i]['植物性营养物量']<a):
sub_sorted.append(1-(a-dates.iloc[i]['植物性营养物量'])/M4)
elif(dates.iloc[i]['植物性营养物量']>b):
sub_sorted.append(1-(dates.iloc[i]['植物性营养物量']-b)/M4)
else:
sub_sorted.append(1)
到目前为止,已经将三个非极大值指标转换为极大值指标
ox_Z=[]
PH_Z=[]
bac_Z=[]
sub_Z=[]
ox_sorted=dates['含氧量']
for i in ox_sorted:
ox_Z.append(i*i)
for i in PH值_sorted:
PH_Z.append(i*i)
for j in bac_sorted:
bac_Z.append(j*j)
for k in sub_sorted:
sub_Z.append(k*k)
ox_Z_Sum=sum(ox_Z)
PH_Z_Sum=sum(PH_Z)
bac_Z_Sum=sum(bac_Z)
sub_Z_Sum=sum(sub_Z)
Z1=[]
Z2=[]
Z3=[]
Z4=[]
for i in ox_sorted:
Z1.append(i/ox_Z_Sum*0.5)
for i in PH值_sorted:
Z2.append(i/PH_Z_Sum*0.5)
for i in bac_sorted:
Z3.append(i/bac_Z_Sum*0.5)
for i in sub_sorted:
Z4.append(i/sub_Z_Sum*0.5)
dic={'ox':Z1,
'PH':Z2,
'bac':Z3,
'sub':Z4
}
Z=DataFrame(dic)
max_list=[]
min_list=[]
max_list.append(Z['ox'].max())
max_list.append(Z['PH'].max())
max_list.append(Z['bac'].max())
max_list.append(Z['sub'].max())
min_list.append(Z['ox'].min())
min_list.append(Z['PH'].min())
min_list.append(Z['bac'].min())
min_list.append(Z['sub'].min())