def computeRankMetrics(self, X, Y, indexList, bestLearners, standardiserY, labelIndex): #Some code to do ranking using the learner predictors i = 0 rankMetrics = numpy.zeros((len(indexList), self.boundsList[labelIndex].shape[0]-1)) for idxtr, idxts in indexList: logging.info("Iteration " + str(i)) trainX, testX = X[idxtr, :], X[idxts, :] trainY, testY = Y[idxtr], Y[idxts] bestLearners[i].learnModel(trainX, trainY) predY = bestLearners[i].predict(testX) gc.collect() #Now output 3 sets of ranked scores predY = standardiserY.unstandardiseArray(predY) testY = standardiserY.unstandardiseArray(testY) YScores = MetabolomicsUtils.scoreLabels(predY, self.boundsList[labelIndex]) YIndList = MetabolomicsUtils.createIndicatorLabel(testY, self.boundsList[labelIndex]) for j in range(self.boundsList[labelIndex].shape[0]-1): rankMetrics[i, j] = Evaluator.auc(YScores[:, j], YIndList[j]) i += 1 logging.debug(rankMetrics) return rankMetrics
def meanAUC(self, predY, testY, labelIndex, standardiserY): predY = standardiserY.unstandardiseArray(predY) testY = standardiserY.unstandardiseArray(testY) YScores = MetabolomicsUtils.scoreLabels(predY, self.boundsList[labelIndex]) YIndList = MetabolomicsUtils.createIndicatorLabel(testY, self.boundsList[labelIndex]) rankMetrics = numpy.zeros(self.boundsList[labelIndex].shape[0]-1) for j in range(rankMetrics.shape[0]): rankMetrics[j] = Evaluator.auc(YScores[:, j], YIndList[j]) return numpy.mean(rankMetrics)