Ejemplo n.º 1
0
    def testSetWeight(self):
        #Try weight = 0 and weight = 1
        decisionTree = DecisionTree()
        decisionTree.setWeight(0.0)
        decisionTree.learnModel(self.X, self.y)

        predY = decisionTree.predict(self.X)
        self.assertTrue((predY == numpy.zeros(predY.shape[0])).all())

        decisionTree.setWeight(1.0)
        decisionTree.learnModel(self.X, self.y)
        predY = decisionTree.predict(self.X)
        self.assertTrue((predY == numpy.ones(predY.shape[0])).all())
Ejemplo n.º 2
0
    def testPredict2(self):
        #We play around with parameters to maximise AUC on the IGF1_0-Haar data
        dataDir = PathDefaults.getDataDir()
        fileName = dataDir + "IGF1_0-Haar.npy"

        XY = numpy.load(fileName)
        X = XY[:, 0:XY.shape[1]-1]
        y = XY[:, XY.shape[1]-1].ravel()

        weight = numpy.bincount(numpy.array(y, numpy.int))[0]/float(y.shape[0])
        #weight = 0.5
        #weight = 0.9

        folds = 3
        decisionTree = DecisionTree()
        decisionTree.setWeight(weight)
        decisionTree.setMaxDepth(50)
        #decisionTree.setMinSplit(100)
        mean, var = decisionTree.evaluateCv(X, y, folds, Evaluator.auc)
        logging.debug("AUC = " + str(mean))
        logging.debug("Var = " + str(var))