P7 = [1, 1, 1, 1, 1, 1]
P8 = [0, 0, 1, 1, 1, 1]
P9 = [0, 1, 0, 1, 0, 1]

p_list = [P1, P2, P3, P4, P5, P6, P7, P8, P9]

# support
set1 = [[0], [2], [5]]
set2 = [[0], [1], [2], [0, 2], [3], [4], [5], [2, 5]]
set3 = [[0], [1], [0, 1], [2], [0, 2], [3], [2, 3], [4], [0, 4], [2, 4], [5],
        [2, 5], [3, 5]]
set4 = ([[0], [1], [0, 1], [2], [0, 2], [1, 2], [0, 1, 2], [3], [1, 3], [2, 3],
         [4], [0, 4], [1, 4], [0, 1, 4], [2, 4], [0, 2, 4], [3, 4], [2, 3, 4],
         [5], [0, 5], [1, 5], [2, 5], [0, 2, 5], [3, 5], [2, 3, 5]])

print('A:', sim.support_mult(p_list, set1))
print('B:', sim.support_mult(p_list, set2))
print('C:', sim.support_mult(p_list, set3))
print('D:', sim.support_mult(p_list, set4))

# naive bayes
class_list = [0, 0, 0, 1, 1, 1, 2, 2, 2]
indx_list = [0, 1]
equal_to = [1, 0]

p = sim.naive_bayes(p_list, class_list, 2, indx_list, equal_to, 3)
print('p:', p)

# similarity measures
smc = sim.smc(P2, P6)
j = sim.j_coeff(P2, P7)
Ejemplo n.º 2
0
O5 = [1, 0, 1, 0, 0, 1, 0, 1]
O6 = [1, 0, 0, 1, 0, 1, 1, 0]
O7 = [0, 1, 1, 0, 0, 1, 0, 1]
O8 = [0, 1, 1, 0, 1, 0, 0, 1]
O9 = [0, 1, 0, 1, 1, 0, 1, 0]
O10 = [0, 1, 0, 1, 0, 1, 1, 0]

o_list = [O1, O2, O3, O4, O5, O6, O7, O8, O9, O10]
indx_list = [[0], [1], [2], [4], [5], [6], [7]]
indx_list2 = [[0], [1], [2], [4], [5], [6], [7], [0, 2], [0, 4], [0, 6],
              [2, 4], [2, 7], [4, 6]]
indx_list3 = [[0], [1], [2], [4], [5], [6], [7], [0, 2], [0, 4], [0, 6],
              [2, 4], [2, 7], [4, 6], [0, 2, 4]]
indx_list4 = [[0], [1], [2], [4], [5], [6], [7], [0, 2], [0, 4], [0, 6],
              [2, 4], [2, 7], [4, 6], [0, 2, 4], [0, 2, 6]]

print("supp A:", sim.support_mult(o_list, indx_list))
print("supp B:", sim.support_mult(o_list, indx_list2))
print("supp C:", sim.support_mult(o_list, indx_list3))
print("supp D:", sim.support_mult(o_list, indx_list4))

a_left = [0, 2]
a_right = [4, 6]
print('conf:', sim.conf(o_list, a_left, a_right))

class_list = [1, 0, 0, 1, 2, 0, 2, 2, 0, 2]
indx_list = [1, 2]

p = sim.naive_bayes(o_list, class_list, 2, indx_list, 3)
print('p', p)
p_list = [P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15]

PC = 1
PCC = 2
HTN = 3
DM = 4
CAD = 5
RBC = 0

A = [[PC], [PCC], [HTN], [DM]]
B = [[PC], [PCC], [HTN], [DM], [PC, PCC], [PC, HTN], [PCC, HTN]]
C = [[PC], [PCC], [HTN], [DM], [PC, PCC], [PC, HTN], [PC, DM], [PCC, HTN]]
D = [[PC], [PCC], [HTN], [DM], [PC, PCC], [PC, HTN], [PC, DM], [PCC, HTN],
     [PC, PCC, HTN]]

print('A:', sim.support_mult(p_list, A))
print('B:', sim.support_mult(p_list, B))
print('C:', sim.support_mult(p_list, C))
print('D:', sim.support_mult(p_list, D))

supp = sim.support(p_list, [RBC, PC, CAD])
conf = sim.conf(p_list, [RBC, PC], [CAD])

print('supp:', supp)
print('conf:', conf)

# knn with custom distance measure
output_list = []
for val in p_list:
    output_list.append(round(1 / sim.smc(val, P5), 3))