diff --git a/.gitignore b/.gitignore index b08dd55..fd9d6d8 100644 --- a/.gitignore +++ b/.gitignore @@ -402,5 +402,6 @@ mlartifacts/ model/ venv/ dist/ +temp/ .idea/ diff --git a/anomaly-detector/anomaly_detector/multivariate/model.py b/anomaly-detector/anomaly_detector/multivariate/model.py index ecbfa70..e6f8abd 100644 --- a/anomaly-detector/anomaly_detector/multivariate/model.py +++ b/anomaly-detector/anomaly_detector/multivariate/model.py @@ -47,7 +47,7 @@ def __init__(self): self.variables: Optional[List[str]] = None def fit(self, data: pd.DataFrame, params: Dict[str, Any] = None) -> None: - variables, values, config = self._verify_data_and_params(data, params) + variables, values, config = self._process_data_and_params(data, params) self.config = config self.variables = variables _window = self.config.threshold_window + self.config.input_size @@ -211,14 +211,17 @@ def evaluate_epoch(self, model, criterion, dataloader): def predict( self, context, data: pd.DataFrame, params: Optional[Dict[str, Any]] = None ): - variables, values, _ = self._verify_data_and_params(data, params) + variables, values, _ = self._process_data_and_params(data, params) if self.model is None: try: self.load_checkpoint(self.model_path) except Exception as ex: raise ValueError(f"Cannot load model. Please train model. {repr(ex)}") - + if len(values) < self.config.threshold_window + self.config.input_size: + raise ValueError( + f"Not enough data. Minimum size is {self.config.threshold_window + self.config.input_size}" + ) hard_th_upper = max(MultiADConstants.ANOMALY_UPPER_THRESHOLD, self.threshold) hard_th_lower = min(MultiADConstants.ANOMALY_LOWER_THRESHOLD, self.threshold) torch.manual_seed(self.config.seed) @@ -382,7 +385,7 @@ def compute_thresholds(self, data) -> (float, float, float): train_score_max = np.max(train_scores) return threshold, train_score_max, train_score_min - def _verify_data_and_params(self, data: pd.DataFrame, params: Dict[str, Any] = None): + def _process_data_and_params(self, data: pd.DataFrame, params: Dict[str, Any] = None): if params is None: params = {}