Пример #1
0
    def predictWithQualityMetrics(self, trainingResult, testData,testGroundTruth):

        # Retrieve predicted labels

        predictedLabels = BinarySVM.predict (self, trainingResult, testData)

        # Create a quality metric set object to compute quality metrics of the SVM algorithm
        qualityMetricSet = quality_metric_set.Batch()

        input = qualityMetricSet.getInputDataCollection().getInput(quality_metric_set.confusionMatrix)

        input.set(binary_confusion_matrix.predictedLabels,   predictedLabels)
        input.set(binary_confusion_matrix.groundTruthLabels, testGroundTruth)

        # Compute quality metrics and get the quality metrics
        # returns ResultCollection class from svm.quality_metric_set
        qualityMetricSetResult = qualityMetricSet.compute()
        return predictedLabels, qualityMetricSetResult
Пример #2
0
 def _computeTwoclassQualityMetrics(self):
     # Alg object for quality metrics computation
     quality_alg = twoclass_quality.Batch()
     # Get access to the input parameter
     input = quality_alg.getInputDataCollection().getInput(
             twoclass_quality.confusionMatrix)
     # Pass ground truth and predictions as input
     input.set(binary_confusion_matrix.groundTruthLabels, self._truth)
     input.set(binary_confusion_matrix.predictedLabels, self._predictions)
     # Compute confusion matrix
     confusion = quality_alg.compute().getResult(twoclass_quality.confusionMatrix)
     # Retrieve quality metrics from the confusion matrix
     metrics = confusion.get(binary_confusion_matrix.binaryMetrics)
     # Convert the metrics into a Python namedtuple and return it
     block = BlockDescriptor_Float64()
     metrics.getBlockOfRows(0, 1, readOnly, block)
     x = block.getArray().flatten()
     self._metrics = TwoClassMetrics(*x)
     metrics.releaseBlockOfRows(block)