-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: disentangle threshold selection from the main model (#89)
* threshold estimators as separate models * remove threshold estimating from autoencoders * simplify mlflow model saving * mlflow now only supports saving per artifact * registry load function now returns a dataclass instead of dict * replace mlflow with mlflow-skinny to reduce unwanted dependencies Signed-off-by: Avik Basu <[email protected]>
- Loading branch information
Showing
17 changed files
with
528 additions
and
1,110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import numpy as np | ||
from numpy.typing import NDArray | ||
from sklearn.base import BaseEstimator | ||
|
||
|
||
class StdDevThreshold(BaseEstimator): | ||
def __init__( | ||
self, | ||
std_factor: float = 3.0, | ||
min_threshold: float = 0.1 | ||
): | ||
self.std_factor = std_factor | ||
self.min_threshold = min_threshold | ||
|
||
self._std = None | ||
self._mean = None | ||
self._threshold = None | ||
|
||
@property | ||
def mean(self): | ||
return self._mean | ||
|
||
@property | ||
def std(self): | ||
return self._std | ||
|
||
@property | ||
def threshold(self): | ||
return self._threshold | ||
|
||
def fit(self, X, y=None): | ||
self._std = np.std(X, axis=0) | ||
self._mean = np.mean(X, axis=0) | ||
self._threshold = self._mean + (self.std_factor * self._std) | ||
self._threshold[self._threshold < self.min_threshold] = self.min_threshold | ||
|
||
return self | ||
|
||
def predict(self, X: NDArray[float]) -> NDArray[float]: | ||
anomaly_scores = X / self.threshold | ||
return anomaly_scores |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from numalogic.registry.artifact import ArtifactManager | ||
from numalogic.registry.artifact import ArtifactData | ||
|
||
try: | ||
from numalogic.registry.mlflow_registry import MLflowRegistrar | ||
except ImportError: | ||
__all__ = ["ArtifactManager"] | ||
__all__ = ["ArtifactManager", "ArtifactData"] | ||
else: | ||
__all__ = ["ArtifactManager", "MLflowRegistrar"] | ||
__all__ = ["ArtifactManager", "ArtifactData", "MLflowRegistrar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.