def flag_anomaly(self, X) -> np.ndarray: """ Flag the data point as an anomaly if the probability surpass epsilon (threshold). Args: X (numpy.ndarray or pandas.DataFrame): data to flag as an anomaly or not. Returns: numpy.ndarray: list of bool telling if a data point is an anomaly or not. """ if not self.check_if_trained(): raise ModelNotTrained("The model has not been trained!") probabilities = self.predict(X) return probabilities < self._epsilon
def flag_anomaly(self, X) -> np.ndarray: """ Flags as anomaly or not the data points. Args: X (numpy.ndarray or pandas.DataFrame): data. Returns: np.ndarray: list of bool telling if a data point is an anomaly or not. """ if not self.check_if_trained(): raise ModelNotTrained("The model has not been trained!") scores = self.predict(X) return scores > self._threshold
def flag_anomaly(self, X) -> np.ndarray: """ Flag a data point as an anomaly or as an inlier. If the score from the predict method is negative, then it's an anomaly, if it's positive then it's an inlier. Args: X (numpy.ndarray or pandas.DataFrame): data to be flagged. Returns: numpy.ndarray: list containing bool values telling if data point is an anomaly or not. """ if not self.check_if_trained(): raise ModelNotTrained("The model has not been trained!") scores = self.predict(X) return scores < 0
def flag_anomaly(self, X) -> np.ndarray: """ Flag the data points as anomaly if the calculated Mahalanobis distance surpass a established threshold. Args: X (numpy.ndarray or pandas.DataFrame): data to flag as anomalous or not anomalous. Returns: numpy.ndarray: list of booleans telling if point is anomalous or not. """ if not self.check_if_trained(): raise ModelNotTrained("The model has not been trained!") distances = self.predict(X) return distances > self._threshold
def flag_anomaly(self, X) -> np.ndarray: """ Flag a data point as an anomaly if the MAE (Mean Absolute Error) is higher than the established threshold. Args: X (numpy.ndarray or pandas.DataFrame): data Returns: numpy.ndarray: list containing bool values telling if data point is an anomaly or not. """ if not self.check_if_trained(): raise ModelNotTrained("The model has not been trained!") predict = self._autoencoder.predict(X) loss = self.mean_absolute_error(X, predict) return loss > self._threshold