(self,inputs,targets)
Confusion matrix
Confusion matrix
Confusion matrix
def confmat(self,inputs,targets):
        """Confusion matrix"""

        # Add the inputs that match the bias node
        inputs = np.concatenate((inputs,-np.ones((np.shape(inputs)[0],1))),axis=1)
        outputs = self.mlpfwd(inputs)
        
        nclasses = np.shape(targets)[1]

        if nclasses==1:
            nclasses = 2
            outputs = np.where(outputs>0.5,1,0)
        else:
            # 1-of-N encoding
            outputs = np.argmax(outputs,1)
            targets = np.argmax(targets,1)

        cm = np.zeros((nclasses,nclasses))
        for i in range(nclasses):
            for j in range(nclasses):
                cm[i,j] = np.sum(np.where(outputs==i,1,0)*np.where(targets==j,1,0))

        print "Confusion matrix is:"
        print cm
        print "Percentage Correct: ",np.trace(cm)/np.sum(cm)*100
def confmat ( self , inputs , targets ) : # Add the inputs that match the bias node inputs = np . concatenate ( ( inputs , - np . ones ( ( np . shape ( inputs ) [ 0 ] , 1 ) ) ) , axis = 1 ) outputs = self . mlpfwd ( inputs ) nclasses = np . shape ( targets ) [ 1 ] if nclasses == 1 : nclasses = 2 outputs = np . where ( outputs > 0.5 , 1 , 0 ) else : # 1-of-N encoding outputs = np . argmax ( outputs , 1 ) targets = np . argmax ( targets , 1 ) cm = np . zeros ( ( nclasses , nclasses ) ) for i in range ( nclasses ) : for j in range ( nclasses ) : cm [ i , j ] = np . sum ( np . where ( outputs == i , 1 , 0 ) * np . where ( targets == j , 1 , 0 ) ) print "Confusion matrix is:" print cm print "Percentage Correct: " , np . trace ( cm ) / np . sum ( cm ) * 100