def get_ConfMatrix(self,TESTSET): CONF=[[0,0,0],[0,0,0],[0,0,0]] for i in range(len(TESTSET)): for j in range(len(TESTSET[i])): Max=-100000000000.0 index=-1 for k in range(3): if(Max<((self.g_x[k][0]*TESTSET[i][j][0])+(self.g_x[k][1]*TESTSET[i][j][1])+self.g_x[k][2])): Max=(self.g_x[k][0]*TESTSET[i][j][0])+(self.g_x[k][1]*TESTSET[i][j][1])+self.g_x[k][2] index=k CONF[i][index]=CONF[i][index]+1 for i in range(3): for j in range(3): print(CONF[i][j], end=" ") print("") sf.get_Score(CONF)
def get_ConfMatrix(self, TESTSET): CONF = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] self.Class1_test_Matrix = sf.get_Matrix(TESTSET[0]) self.Class2_test_Matrix = sf.get_Matrix(TESTSET[1]) self.Class3_test_Matrix = sf.get_Matrix(TESTSET[2]) self.mew = [] for i in range(len(TESTSET)): self.mew.append(sf.Mean(TESTSET[i])) # print (self.Class1_test_Matrix,self.Class2_test_Matrix) inv_class1 = sf.get_Inverse(self.Class1_test_Matrix) inv_class2 = sf.get_Inverse(self.Class2_test_Matrix) inv_class3 = sf.get_Inverse(self.Class3_test_Matrix) temp1 = sf.get_Matrix(TESTSET[0]) temp2 = sf.get_Matrix(TESTSET[1]) temp3 = sf.get_Matrix(TESTSET[2]) # print (temp1,temp2) for i in range(len(TESTSET)): for j in range(len(TESTSET[i])): temp = [0, 0, 0] val1 = self.getGx(TESTSET[i][j][0], TESTSET[i][j][1], inv_class1, self.mew[0], temp1, len(TESTSET[0])) val2 = self.getGx(TESTSET[i][j][0], TESTSET[i][j][1], inv_class2, self.mew[1], temp2, len(TESTSET[1])) val3 = self.getGx(TESTSET[i][j][0], TESTSET[i][j][1], inv_class3, self.mew[2], temp3, len(TESTSET[2])) if (max(val1, val2, val3) == val1): CONF[i][0] = CONF[i][0] + 1 elif (max(val1, val2, val3) == val2): CONF[i][1] = CONF[i][1] + 1 else: CONF[i][2] = CONF[i][2] + 1 for i in range(3): for j in range(3): print(CONF[i][j], end=" ") print("") sf.get_Score(CONF)
def get_ConfMatrix_pair(self, TESTSET): CONF=[[0,0],[0,0]] arr=[0,1] for i in arr: for j in range(len(TESTSET[i])): Max=-100000000000.0 index=-1 for k in arr: if(Max<((self.g_x[k][0]*TESTSET[i][j][0])+(self.g_x[k][1]*TESTSET[i][j][1])+self.g_x[k][2])): Max=(self.g_x[k][0]*TESTSET[i][j][0])+(self.g_x[k][1]*TESTSET[i][j][1])+self.g_x[k][2] index=k CONF[i][index]=CONF[i][index]+1 for i in range(2): for j in range(2): print(CONF[i][j], end=" ") print("") print("For class1 and 2") sf.get_Score(CONF) CONF=[[0,0],[0,0]] arr=[1,2] for i in range(2): for j in range(len(TESTSET[arr[i]])): Max=-100000000000.0 index=-1 for k in range(2): if(Max<((self.g_x[arr[k]][0]*TESTSET[arr[i]][j][0])+(self.g_x[arr[k]][1]*TESTSET[arr[i]][j][1])+self.g_x[arr[k]][2])): Max=((self.g_x[arr[k]][0]*TESTSET[arr[i]][j][0])+(self.g_x[arr[k]][1]*TESTSET[arr[i]][j][1])+self.g_x[arr[k]][2]) index=k CONF[i][index]=CONF[i][index]+1 for i in range(2): for j in range(2): print(CONF[i][j], end=" ") print("") print("For class2 and 3") sf.get_Score(CONF) CONF=[[0,0],[0,0]] arr=[0,2] for i in range(2): for j in range(len(TESTSET[arr[i]])): Max=-100000000000.0 index=-1 for k in range(2): if(Max<((self.g_x[arr[k]][0]*TESTSET[arr[i]][j][0])+(self.g_x[arr[k]][1]*TESTSET[arr[i]][j][1])+self.g_x[arr[k]][2])): Max=((self.g_x[arr[k]][0]*TESTSET[arr[i]][j][0])+(self.g_x[arr[k]][1]*TESTSET[arr[i]][j][1])+self.g_x[arr[k]][2]) index=k CONF[i][index]=CONF[i][index]+1 for i in range(2): for j in range(2): print(CONF[i][j], end=" ") print("") print("For class1 and 3") sf.get_Score(CONF)
def get_ConfMatrix_pair(self, TESTSET): CONF = [[0, 0], [0, 0]] temp1 = sf.get_Matrix(TESTSET[0]) temp2 = sf.get_Matrix(TESTSET[1]) temp3 = sf.get_Matrix(TESTSET[2]) self.mew = [] for i in range(len(TESTSET)): self.mew.append(sf.Mean(TESTSET[i])) inv_class1 = sf.get_Inverse(temp1) inv_class2 = sf.get_Inverse(temp2) inv_class3 = sf.get_Inverse(temp3) self.Class1_test_Matrix = sf.get_Matrix(TESTSET[0]) self.Class2_test_Matrix = sf.get_Matrix(TESTSET[1]) self.Class3_test_Matrix = sf.get_Matrix(TESTSET[2]) # for i in range(len(TESTSET)): case = [0, 1] for i in case: for j in range(len(TESTSET[i])): temp = [0, 0, 0] val1 = self.getGx(TESTSET[i][j][0], TESTSET[i][j][1], inv_class1, self.mew[0], self.Class1_test_Matrix, len(TESTSET[0])) val2 = self.getGx(TESTSET[i][j][0], TESTSET[i][j][1], inv_class2, self.mew[1], self.Class2_test_Matrix, len(TESTSET[1])) if (val1 > val2): CONF[i][0] = CONF[i][0] + 1 else: CONF[i][1] = CONF[i][1] + 1 print("Confusion Matrix for class 1 & 2") for i in range(2): for j in range(2): print(CONF[i][j], end=" ") print("") sf.get_Score(CONF) CONF = [[0, 0], [0, 0]] case = [1, 2] for i in case: for j in range(len(TESTSET[i])): temp = [0, 0, 0] val2 = self.getGx(TESTSET[i][j][0], TESTSET[i][j][1], inv_class2, self.mew[1], self.Class2_test_Matrix, len(TESTSET[1])) val3 = self.getGx(TESTSET[i][j][0], TESTSET[i][j][1], inv_class3, self.mew[2], self.Class3_test_Matrix, len(TESTSET[2])) if (val2 > val3): CONF[i - 1][0] = CONF[i - 1][0] + 1 else: CONF[i - 1][1] = CONF[i - 1][1] + 1 print("Confusion Matrix for class 2 & 3") for i in range(2): for j in range(2): print(CONF[i][j], end=" ") print("") sf.get_Score(CONF) CONF = [[0, 0], [0, 0]] case = [0, 2] for i in case: for j in range(len(TESTSET[i])): temp = [0, 0, 0] val1 = self.getGx(TESTSET[i][j][0], TESTSET[i][j][1], inv_class1, self.mew[0], self.Class1_test_Matrix, len(TESTSET[0])) val3 = self.getGx(TESTSET[i][j][0], TESTSET[i][j][1], inv_class3, self.mew[2], self.Class3_test_Matrix, len(TESTSET[2])) k = 0 if (i == 2): k = 1 if (val1 > val3): CONF[k][0] = CONF[k][0] + 1 else: CONF[k][1] = CONF[k][1] + 1 print("Confusion Matrix for class 2 & 3") for i in range(2): for j in range(2): print(CONF[i][j], end=" ") print("") sf.get_Score(CONF)