def train(self, messageList):
        globalClassifier = self._globalClassifier
        localClassifier = self._localClassifier
        trainLog = ""
        nFolds = 5

        msgList = map(lambda x: x[0], messageList)
        y = np.array(map(lambda x: 1 if x[1] == 'pos' else 0, messageList))

        #--- obtain global decision function list
        globalDFList = []
        for msg in msgList:
            v = globalClassifier.predictScore(msg)
            globalDFList.append(v['pos'])

        tt = tic()
        #--- obtain local decision function list (by cross-prediction)
        if (sum(y) < 2):
            #--- if there are less than 2 positive data points, set alpha=0
            trainLog += "There are less than 2 positive data points. setting maxAlpha=0\n"
            maxAlpha = 0
        else:
            #--- split into 5 and cross-predict decision function
            localDFList = [float('nan')] * len(messageList)
            folds = StratifiedKFold(y, nFolds)
            for trainIdx, testIdx in folds:
                train = [messageList[i] for i in trainIdx]
                test = [messageList[i] for i in testIdx]

                tmpClassifier = copy.deepcopy(localClassifier)
                tmpClassifier.train(train)

                curDFList = []
                for x in test:
                    v = tmpClassifier.predictScore(x[0])
                    curDFList.append(v['pos'])

                for i in range(len(test)):
                    localDFList[testIdx[i]] = curDFList[i]
            assert(countTruth(lambda x: np.isnan(x), localDFList) == 0)

            #--- try many alpha's, and measure F1
            f1List = []
            alphaList = np.linspace(0.0, 1.0, 101)
            for alpha in alphaList:
                combinedDFList = [(1 - alpha) * globalDFList[i] + alpha * localDFList[i]
                                  for i in range(len(globalDFList))]
                predy = [1 if v >= 0.0 else 0 for v in combinedDFList]
                #- measure F1
                f1 = metrics.f1_score(y, predy)
                f1List.append(f1)

            #--- pick alpha that maximizes F1
            trainLog += "Finding alpha maximizing F1...\n"
            maxF1 = np.max(f1List)
            maxIdx = np.where(np.array(f1List) == maxF1)
            maxIdx = maxIdx[0]
            assert(len(maxIdx) != 0)
            candidateMaxAlpha = [alphaList[i] for i in maxIdx]
            maxAlpha = np.median(candidateMaxAlpha)

            trainLog += "max(f1List) = %.3f\n" % maxF1
            trainLog += "argmax_alpha = \n%s\n" % str(
                np.array([alphaList[i] for i in maxIdx]))
            trainLog += "chosen alpha by median = %.3f\n" % maxAlpha

            #--- train local classifier using all data
            localClassifier.train(binaryLabeledMessageList)

        elapsed = toc(tt)
        trainLog += "Time taken for training: %.3f (sec)\n" % elapsed

        self._localClassifier = localClassifier
        self._alpha = maxAlpha
        self._trainLog = trainLog

        #--- learn sigmoid
        yDeci = [self.predictScore(msg)['pos'] for msg in messageList]
        yy = [1 if v == 1 else -1 for v in y]
        [A, B] = platt.SigmoidTrain(yDeci, yy)
        plattModel = [A, B]

        self._plattModel = plattModel
        pass
dataset/ETHPy150Open dssg/ushine-learning/dssg/classifier.py/DssgBinaryClassifierAdaptiveInterpolation.train/original