def predict(self, trainingResult, testData):

        if self.method == 'boser':
            from daal.algorithms.svm.training import boser
            algorithm = prediction.Batch(method=boser, fptype=self.dtype)

        if self.kernel == 'linear':
            algorithm.parameter.kernel = kernel_function.linear.Batch()
        elif self.kernel == 'rbf':
            algorithm.parameter.kernel = kernel_function.rbf.Batch()

        algorithm.input.setTable(classifier.prediction.data, testData)
        algorithm.input.setModel(classifier.prediction.model,
                                 trainingResult.get(classifier.training.model))
        algorithm.compute()
        predictionResult = algorithm.getResult()
        predictedResponses = predictionResult.get(
            classifier.prediction.prediction)
        '''
		block = BlockDescriptor ()
		predictedResponses.getBlockOfRows (0, predictedResponses.getNumberOfRows (), readWrite, block)
		predictArray = block.getArray ()
		predictArray[predictArray < 0] = -1
		predictArray[predictArray >= 0] = 1
		predictedResponses.releaseBlockOfRows (block)
		'''
        return predictedResponses
    def training(self, trainData, trainDependentVariables):

        #Set algorithms parameters
        if self.method == 'boser':
            from daal.algorithms.svm.training import boser
            trainingBatch = training.Batch(method=boser, fptype=self.dtype)
            predictionBatch = prediction.Batch()

        if self.kernel == 'linear':
            trainingBatch.parameter.kernel = kernel_function.linear.Batch(
                method=boser, fptype=self.dtype)
            trainingBatch.parameter.k = self.k
            trainingBatch.parameter.b = self.b
        elif self.kernel == 'rbf':
            trainingBatch.parameter.kernel = kernel_function.rbf.Batch(
                method=boser, fptype=self.dtype)
            trainingBatch.parameter.sigma = self.sigma

        trainingBatch.parameter.cacheSize = self.cachesize
        trainingBatch.parameter.C = self.C
        trainingBatch.parameter.accuracyThreshold = self.tolerence
        trainingBatch.parameter.tau = self.tau
        trainingBatch.parameter.maxIterations = self.maxIterations
        trainingBatch.parameter.doShrinking = self.doShrinking

        algorithm = multi_class_classifier.training.Batch(self.classes)
        algorithm.parameter.training = trainingBatch
        algorithm.parameter.prediction = predictionBatch
        algorithm.input.set(classifier.training.data, trainData)
        algorithm.input.set(classifier.training.labels,
                            trainDependentVariables)
        trainingResult = algorithm.compute()
        return trainingResult
Exemplo n.º 3
0
    def predict(self, trainingResult, testData): #give other parameters

        if self.method == 'boser':
            from  daal.algorithms.svm.training import boser
            predictionBatch = prediction.Batch (method=boser, fptype=self.dtype)
            trainingBatch = training.Batch (method=boser, fptype=self.dtype)

        if self.kernel == 'linear':
            predictionBatch.parameter.kernel = kernel_function.linear.Batch ()
        elif self.kernel == 'rbf':
            predictionBatch.parameter.kernel = kernel_function.rbf.Batch ()

        algorithm = multi_class_classifier.prediction.Batch (self.classes)
        algorithm.parameter.training = trainingBatch
        algorithm.parameter.prediction = predictionBatch
        algorithm.input.setTable (classifier.prediction.data, testData)
        algorithm.input.setModel (classifier.prediction.model, trainingResult.get (classifier.training.model))
        algorithm.compute ()
        predictionResult = algorithm.getResult()
        predictedResponses = predictionResult.get (classifier.prediction.prediction)
        # Change the predicted values to 1 and -1
        return predictedResponses