コード例 #1
0
ファイル: deepnet.py プロジェクト: themarkib/python-1
    def predict_operating(self, input_data, operating_point=None):
        """Computes the prediction based on a user-given operating point.

        """

        kind, threshold, positive_class = parse_operating_point( \
            operating_point, ["probability"], self.class_names)
        predictions = self.predict_probability(input_data, False)
        position = self.class_names.index(positive_class)
        if predictions[position][kind] > threshold:
            prediction = predictions[position]
        else:
            # if the threshold is not met, the alternative class with
            # highest probability or confidence is returned
            predictions.sort( \
                key=cmp_to_key( \
                lambda a, b: self._sort_predictions(a, b, kind)))
            prediction = predictions[0 : 2]
            if prediction[0]["category"] == positive_class:
                prediction = prediction[1]
            else:
                prediction = prediction[0]
        prediction["prediction"] = prediction["category"]
        del prediction["category"]
        return prediction
コード例 #2
0
ファイル: fusion.py プロジェクト: bergsail/python
    def predict_operating(self, input_data,
                          missing_strategy=LAST_PREDICTION,
                          operating_point=None):
        """Computes the prediction based on a user-given operating point.

        """
        # only probability is allowed as operating kind
        operating_point.update({"kind": "probability"})
        kind, threshold, positive_class = parse_operating_point( \
            operating_point, OPERATING_POINT_KINDS, self.class_names)
        predictions = self.predict_probability(input_data,
                                               missing_strategy, False)

        position = self.class_names.index(positive_class)
        if predictions[position][kind] > threshold:
            prediction = predictions[position]
        else:
            # if the threshold is not met, the alternative class with
            # highest probability or confidence is returned
            predictions.sort( \
                key=cmp_to_key( \
                lambda a, b: self._sort_predictions(a, b, kind)))
            prediction = predictions[0: 2]
            if prediction[0]["category"] == positive_class:
                prediction = prediction[1]
            else:
                prediction = prediction[0]
        prediction["prediction"] = prediction["category"]
        del prediction["category"]
        return prediction
コード例 #3
0
    def predict_operating(self,
                          input_data,
                          by_name=True,
                          operating_point=None,
                          compact=False):
        """Computes the prediction based on a user-given operating point.

        """

        kind, threshold, positive_class = parse_operating_point( \
            operating_point, ["probability"], self.class_names)
        predictions = self.predict_probability(input_data, by_name, compact)
        position = self.class_names.index(positive_class)
        if predictions[position][kind] < threshold:
            # if the threshold is not met, the alternative class with
            # highest probability or confidence is returned
            prediction = sorted(predictions, key=lambda x: -x[kind])[0:2]
            if prediction[0]["category"] == positive_class:
                prediction = prediction[1]
            else:
                prediction = prediction[0]
        else:
            prediction = predictions[position]
        prediction["prediction"] = prediction["category"]
        del prediction["category"]
        return prediction
コード例 #4
0
    def predict_operating(self,
                          input_data,
                          missing_strategy=LAST_PREDICTION,
                          operating_point=None):
        """Computes the prediction based on a user-given operating point.

        """
        kind, threshold, positive_class = parse_operating_point( \
            operating_point, OPERATING_POINT_KINDS, self.class_names)

        try:
            predict_method = None
            predict_method = getattr(self, "predict_%s" % kind)

            predictions = predict_method(input_data, missing_strategy, False)
            position = self.class_names.index(positive_class)
        except KeyError:
            raise ValueError("The operating point needs to contain a valid"
                             " positive class, kind and a threshold.")

        if self.regression:
            prediction = predictions
        else:
            position = self.class_names.index(positive_class)
            if predictions[position][kind] > threshold:
                prediction = predictions[position]
            else:
                # if the threshold is not met, the alternative class with
                # highest probability or confidence is returned
                predictions.sort( \
                    key=cmp_to_key( \
                    lambda a, b: self._sort_predictions(a, b, kind)))
                prediction = predictions[0:2]
                if prediction[0]["category"] == positive_class:
                    prediction = prediction[1]
                else:
                    prediction = prediction[0]
            prediction["prediction"] = prediction["category"]
            del prediction["category"]
        return prediction