Example #1
0
    def send_feedback(self, X, feature_names, reward, truth):
        """ Return outlier labels as part of the feedback loop.
        
        Arguments:
            - X: input data
            - feature_names
            - reward
            - truth: outlier labels
        """
        self.label = truth
        self._labels.append(self.label)
        self._labels = flatten(self._labels)

        scores = performance(self._labels,
                             self._predictions,
                             roll_window=self.roll_window)
        stats = outlier_stats(self._labels,
                              self._predictions,
                              roll_window=self.roll_window)

        convert = flatten([scores, stats])
        metric = []
        for c in convert:  # convert from np to native python type to jsonify
            metric.append(np.asscalar(np.asarray(c)))
        self.metric = metric

        return
 def send_feedback(self,X,feature_names,reward,truth):
     """ Return outlier labels as part of the feedback loop.
     
     Parameters
     ----------
         X : array of the features sent in the original predict request
         feature_names : array of feature names. May be None if not available.
         reward (float): the reward
         truth : array with correct value (optional)
     """
     _ = super().send_feedback(X,feature_names,reward,truth)
     
     # historical reconstruction errors and predictions
     self._mse.append(self.mse)
     self._mse = flatten(self._mse)
     self._predictions.append(self.prediction)
     self._predictions = flatten(self._predictions)
     
     # target labels
     self.label = truth
     self._labels.append(self.label)
     self._labels = flatten(self._labels)
     
     # performance metrics
     scores = performance(self._labels,self._predictions,roll_window=self.roll_window)
     stats = outlier_stats(self._labels,self._predictions,roll_window=self.roll_window)
     
     convert = flatten([scores,stats])
     metric = []
     for c in convert: # convert from np to native python type to jsonify
         metric.append(np.asscalar(np.asarray(c)))
     self.metric = metric
     
     return []