def computePerformance(self, train_indexes, val_ind): '''Check errors of training and validation sets @param train_indexes Tuple that contains indexes of the first and last elements of the training set. @param val_ind Tuple that contains indexes of the first and last elements of the validation set. ''' train_error = 0 train_sampl = train_indexes[1] - train_indexes[ 0] # Count of training samples for i in range(train_indexes[0], train_indexes[1]): train_error = train_error + self.computeMlpError( sample=self.data[i]) self.setTrainError(train_error / train_sampl) if val_ind: val_error = 0 val_sampl = val_ind[1] - val_ind[0] answers = np.ma.zeros(val_sampl) out = np.ma.zeros(val_sampl) for i in xrange(val_ind[0], val_ind[1]): sample = self.data[i] val_error = val_error + self.computeMlpError( sample=self.data[i]) input = np.hstack((sample['state'], sample['factors'])) output = self.getOutput(input) out[i - val_ind[0]] = self.outCategory(output) answers[i - val_ind[0]] = self.outCategory(sample['output']) self.setValError(val_error / val_sampl) depCoef = DependenceCoef(out, answers, expand=True) self.valKappa = depCoef.kappa(mode=None)
def computePerformance(self, train_indexes, val_ind): '''Check errors of training and validation sets @param train_indexes Tuple that contains indexes of the first and last elements of the training set. @param val_ind Tuple that contains indexes of the first and last elements of the validation set. ''' train_error = 0 train_sampl = train_indexes[1] - train_indexes[0] # Count of training samples for i in range(train_indexes[0], train_indexes[1]): train_error = train_error + self.computeMlpError(sample = self.data[i]) self.setTrainError(train_error/train_sampl) if val_ind: val_error = 0 val_sampl = val_ind[1] - val_ind[0] answers = np.ma.zeros(val_sampl) out = np.ma.zeros(val_sampl) for i in xrange(val_ind[0], val_ind[1]): sample = self.data[i] val_error = val_error + self.computeMlpError(sample = self.data[i]) input = np.hstack( (sample['state'],sample['factors']) ) output = self.getOutput(input) out[i-val_ind[0]] = self.outCategory(output) answers[i-val_ind[0]] = self.outCategory(sample['output']) self.setValError(val_error/val_sampl) depCoef = DependenceCoef(out, answers, expand=True) self.valKappa = depCoef.kappa(mode=None)
def train(self): X = np.column_stack((self.data['state'], self.data['factors'])) Y = self.data['output'] self.labelCodes = np.unique(Y) self.logreg.fit(X, Y, maxiter=self.maxiter) out = self.logreg.predict(X) depCoef = DependenceCoef(np.ma.array(out), np.ma.array(Y), expand=True) self.Kappa = depCoef.kappa(mode=None) self.pseudoR = depCoef.correctness(percent=False)
def train(self): X = np.column_stack( (self.data['state'], self.data['factors']) ) Y = self.data['output'] self.labelCodes = np.unique(Y) self.logreg.fit(X, Y, maxiter=self.maxiter) out = self.logreg.predict(X) depCoef = DependenceCoef(np.ma.array(out), np.ma.array(Y), expand=True) self.Kappa = depCoef.kappa(mode=None) self.pseudoR = depCoef.correctness(percent = False)
def test_kappa(self): dc = DependenceCoef(self.Y, self.Y1) #~ table = np.array([ #~ [1, 2, 1], #~ [0, 1, 0], #~ [2, 0, 1], #~ ]) Pa = 3.0/8 Pe = 21.0/64 Pmax = 6.0/8 answer = (Pa - Pe)/(1 - Pe) self.assertEqual(dc.kappa(), answer) answer = (Pa - Pe)/(Pmax - Pe) self.assertEqual(dc.kappa(mode='loc'), answer) answer = (Pmax - Pe)/(1 - Pe) self.assertEqual(dc.kappa(mode='histo'), answer)
def test_kappa(self): dc = DependenceCoef(self.Y, self.Y1) #~ table = np.array([ #~ [1, 2, 1], #~ [0, 1, 0], #~ [2, 0, 1], #~ ]) Pa = 3.0 / 8 Pe = 21.0 / 64 Pmax = 6.0 / 8 answer = (Pa - Pe) / (1 - Pe) self.assertEqual(dc.kappa(), answer) answer = (Pa - Pe) / (Pmax - Pe) self.assertEqual(dc.kappa(mode='loc'), answer) answer = (Pmax - Pe) / (1 - Pe) self.assertEqual(dc.kappa(mode='histo'), answer)