-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclass_transition_matrix.py
94 lines (72 loc) · 2.12 KB
/
class_transition_matrix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import numpy as np
from numpy import genfromtxt
test_y=np.load('test_labels_40ensemble_4classes_fuzzy.npy')
prediction=genfromtxt('prediction_images.csv', delimiter=',')
for i in range(0,np.size(prediction,0)):
x=np.argmax(prediction[i,:])
prediction[i,x]=1
for i in range(0,np.size(prediction,0)):
for j in range(0,np.size(prediction,1)):
if (prediction[i,j]<>1):
prediction[i,j]=0
class1=0
class2=0
class3=0
class4=0
for i in range(0,np.size(test_y,0)):
if (test_y[i,0]==1):
class1=class1+1
if (test_y[i,1]==1):
class2=class2+1
if (test_y[i,2]==1):
class3=class3+1
if (test_y[i,3]==1):
class4=class4+1
print ('class1=')
print (class1)
print ('class2=')
print (class2)
print ('class3=')
print (class3)
print ('class4=')
print (class4)
markov_matrix=np.zeros((4,4))
for i in range(0,np.size(test_y,0)):
if (test_y[i,0]):
if(prediction[i,0]==1):
markov_matrix[0,0]=markov_matrix[0,0]+1
elif(prediction[i,1]==1):
markov_matrix[0,1]=markov_matrix[0,1]+1
elif((prediction[i,2]==1)):
markov_matrix[0,2]=markov_matrix[0,2]+1
elif((prediction[i,3]==1)):
markov_matrix[0,3]=markov_matrix[0,3]+1
if (test_y[i,1]):
if(prediction[i,1]==1):
markov_matrix[1,1]=markov_matrix[1,1]+1
elif(prediction[i,0]==1):
markov_matrix[1,0]=markov_matrix[1,0]+1
elif((prediction[i,2]==1)):
markov_matrix[1,2]=markov_matrix[1,2]+1
elif((prediction[i,3]==1)):
markov_matrix[1,3]=markov_matrix[1,3]+1
if (test_y[i,2]):
if(prediction[i,2]==1):
markov_matrix[2,2]=markov_matrix[2,2]+1
elif(prediction[i,0]==1):
markov_matrix[2,0]=markov_matrix[2,0]+1
elif((prediction[i,1]==1)):
markov_matrix[2,1]=markov_matrix[2,1]+1
elif((prediction[i,3]==1)):
markov_matrix[2,3]=markov_matrix[2,3]+1
if (test_y[i,3]):
if(prediction[i,3]==1):
markov_matrix[3,3]=markov_matrix[3,3]+1
elif(prediction[i,0]==1):
markov_matrix[3,0]=markov_matrix[3,0]+1
elif((prediction[i,1]==1)):
markov_matrix[3,1]=markov_matrix[3,1]+1
elif((prediction[i,2]==1)):
markov_matrix[3,2]=markov_matrix[3,2]+1
print('TRANSITION MATRIX')
print(markov_matrix)