Ejemplo n.º 1
0
    def fit(self, X, **kwargs):

        self._classes = 2

        X = self.normalizer.fit_transform(X)

        self.detector_.fit(X)

        self.decision_scores_ = invert_order(
            self.detector_.decision_function(X))

        self._process_decision_scores()
Ejemplo n.º 2
0
    def decision_function(self, X):
        """Predict raw anomaly scores of X using the fitted detector.
        After invert_order(): the higher score, the more probability of x that is predicted as abnormal

        Parameters
        ----------
        X : numpy array of shape (n_samples, n_features)
            The input samples. Sparse matrices are accepted only
            if they are supported by the base estimator.

        Returns
        -------
        anomaly_scores : numpy array of shape (n_samples,)
            The anomaly score of the input samples.
        """
        # check_is_fitted(self, ['decision_scores_', 'threshold_', 'labels_'])
        return invert_order(self.model_.score_samples(X))
Ejemplo n.º 3
0
    def decision_function(self, X):
        """Predict raw anomaly score of X using the fitted detector.

        The anomaly score of an input sample is computed based on different
        detector algorithms. For consistency, outliers are assigned with
        larger anomaly scores.

        Parameters
        ----------
        X : numpy array of shape (n_samples, n_features)
            The training input samples. Sparse matrices are accepted only
            if they are supported by the base estimator.

        Returns
        -------
        anomaly_scores : numpy array of shape (n_samples,)
            The anomaly score of the input samples.
        """
        # invert outlier scores. Outliers comes with higher outlier scores
        return invert_order(self.model_.decision_function(X))
Ejemplo n.º 4
0
    def decision_function(self, X):
        """Predict raw anomaly scores of X using the fitted detector.

        The anomaly score of an input sample is computed based on the fitted
        detector. For consistency, outliers are assigned with
        larger anomaly scores. so use invert_order

        After invert_order(): the higher score, the more probability of x that is predicted as abnormal

        Parameters
        ----------
        X : numpy array of shape (n_samples, n_features)
            The input samples. Sparse matrices are accepted only
            if they are supported by the base estimator.

        Returns
        -------
        anomaly_scores : numpy array of shape (n_samples,)
            The anomaly score of the input samples.
        """
        # check_is_fitted(self, ['decision_scores_', 'threshold_', 'labels_'])
        return invert_order(logsumexp(self.model_._estimate_weighted_log_prob(X), axis=1))