Skip to content

Commit

Permalink
Removed unused imports and added a condition check for thresholding
Browse files Browse the repository at this point in the history
  • Loading branch information
Velu Prabhakar committed May 5, 2023
1 parent a8bc185 commit 455b325
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions meegkit/lof.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# License: BSD-3-Clause

import logging
import numpy as np
from sklearn.neighbors import LocalOutlierFactor


Expand All @@ -24,7 +23,7 @@ class LOF():
threshold : float
Threshold to define outliers.
Range for this variable can be between 1.0 and any integer.
Theoretical threshold can range anywhere between 1.0 and any integer.
Default: 1.5
It is recommended to perform a CV (e.g., 10-fold) on training
Expand Down Expand Up @@ -69,12 +68,17 @@ def predict(self, X):

if X.ndim == 3: # in case the input data has 3 dimensions (epoched data)
logging.warning('Expected input data with shape (n_channels, n_samples)')
return []

if self.n_neighbors >= X.shape[0]:
logging.warning('Number of neighbours cannot be greater than the '
'number of channels')
return []

if self.threshold < 1.0:
logging.warning('Invalid threshold. Try a positive integer >= 1.0')
return []

clf = LocalOutlierFactor(self.n_neighbors)
logging.debug('[LOF] Predicting bad channels')
clf.fit_predict(X)
Expand Down

0 comments on commit 455b325

Please sign in to comment.