import numpy as np
import pandas as pd
def sep_pro(sep):
count3 = 0
Acc = {}
for key, value in sep.items():
count1 = 0
count2 = 0
count3 += 1
acc = 0
for i in value:
count2 += 1
if i[-1] == 2:
count1 += 1
acc = count1 / count2
if key not in Acc:
Acc[key] = []
Acc[key].append(acc)
return Acc
def sep_class(c):
sep = {}
for i in c:
count = 0
for j in range(len(i[0:6])):
vectors = i[j]
count = vectors * pow(10, 5 - j) + count
if count not in sep:
sep[count] = []
sep[count].append(i)
return sep
def twd(Acc):
POS = {}
BNG = {}
NEG = {}
a = 0.63
b = 0.25
for key, value in Acc.items():
for i in value:
if i > a:
if key not in POS:
POS[key] = i
elif i < b:
if key not in NEG:
NEG[key] = i
else:
if key not in BNG:
print(BNG)
BNG[key] = i
return POS, BNG, NEG
def huafenR(res, res1, u, v):
R1 = {}
R2 = {}
R3 = {}
for key, value in res.items():
for key1, value1 in res1.items():
a = value1-value
if key == key1:
if a > u:
R1[key] = value1
elif a < v:
R3[key] = value1
else:
R2[key] = value1
return R1, R2, R3
testset1 = pd.read_csv("/Users/wupeng/PycharmProjects/two-twd/breast.csv", header=None).values.tolist()
sep = sep_class(testset1)
Acc = sep_pro(sep)
print(Acc)
res = twd(Acc)
testset2 = pd.read_csv("/Users/wupeng/PycharmProjects/two-twd/src/test1.csv", header=None).values.tolist()
sep1 = sep_class(testset2)
Acc1 = sep_pro(sep1)
res1 = twd(Acc1)
u = 0.025
v = -0.015
a = 0
# POS区域的R1,R2,R3
res2 = huafenR(res[0], res1[0], u, v)
# NEG区域的R1,R2,R3
res3 = huafenR(res[2], res1[2], u, v)
CPOS = {}
CBND = res[1]
CNEG = {}
# 初始的POS区域
for key, value in res[0].items():
# POS区域的R1
for key1, value1 in res2[0].items():
# POS区域的R2
if key == key1:
CPOS[key] = value
for key3,value3 in res2[1].items():
if key == key3:
CPOS[key] = value
# CBND的区域
for key, value in res[0].items():
for key1, value1 in res2[2].items():
if key1 == key:
CBND[key] = value
for key, value in res[2].items():
for key4, value4 in res3[0]:
if key == key4:
CBND[key] = value
# CNEG的区域
for key, value in res[2].items():
for key1, value1 in res3[1].items():
if key == key1:
CNEG[key] = value
for key2, value2 in res3[2].items():
if key ==key2:
CNEG[key] = value
print("CPOS", CPOS)
print("CBND", CBND)
print("CNEG", CNEG)
#
# print("POS区域的R1:", res2[0])
# print("POS区域的R2:", res2[1])
# print("POS区域的R3:", res2[2])
#
# print("NEG区域的R1:", res3[0])
# print("NEG区域的R2:", res3[1])
# print("NEG区域的R3:", res3[2])
print("POS :", res[0])
print("POS1:", res1[0])
print("BNG :", res[1])
print("BNG1:", res1[1])
print("NEG: ", res[2])
print("NEG1:", res1[2])
下一篇
mac下用python画图中文不会乱码
2021-06-19