Пример #1
0
	def score_individual(self,ytest,how='tau'):
		"""
		Scores each individual near neighbor.

		Returns
		----------
		dist : 1d array of the average distances for each near neighbor
		score : 2d (num of NN, prediction distance) array of the score values
		"""

		num_neighbors = self.dist.shape[1]
		num_preds = self.ytrain.shape[1]
		score = np.zeros((num_neighbors, num_preds))

		for i in range(num_neighbors):

			ypred = self.ytrain[self.ind[:,i]] # grab all the 1st NN, then 2nd, etc...

			for j in range(num_preds):


				if how == 'classCompare':
					score[i,j] = mets.classCompare(ypred[:,j], ytest[:,j])

				elif how == 'classError':
					score[i,j] = mets.classificationError(ypred[:,j], ytest[:,j])

				elif how == 'tau':
					score[i,j] = mets.kleckas_tau(ypred[:,j], ytest[:,j])

		avg_dist = np.mean(self.dist,axis=0)
		return avg_dist, score
Пример #2
0
	def score(self, ytest, how='tau'):
		"""
		Evalulate the predictions
		Parameters
		----------
		ytest : 2d array containing the targets
		how : string
			how to score the predictions
			-'classCompare' : percent correctly predicted
			-'classError' : Dont use this
			-'tau' : kleckas tau
		"""

		num_preds = ytest.shape[1]

		sc = np.empty((1,num_preds))

		scores = []

		for pred in self.ypred:
			sc = np.empty(pred.shape[1])

			for i in range(pred.shape[1]):

				p = pred[:,i]

				if how == 'classCompare':
					sc[i] = mets.classCompare(p,ytest[:,i])

				elif how == 'classError':
					sc[i] = mets.classificationError(p,ytest[:,i])

				elif how == 'tau':
					sc[i] = mets.kleckas_tau(p,ytest[:,i])

			scores.append(sc)

		scores = np.vstack(scores)
		return scores