Skip to content

Commit

Permalink
evaluators can now be str or function
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol-Srivastava committed Aug 18, 2022
1 parent 6ccaaea commit d4d45de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/menelaus/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ class Ensemble:
def __init__(self, detectors: dict, evaluator, columns: dict = None):
self.detectors = detectors.copy()
self.columns = columns
# XXX - Since rigid type-checking is sort of discouraged in Python
# it makes the most sense to just treat evaluator as (always)
# a function operating on detectors.
self.evaluator = evaluator
# XXX - This type of type-checking is discouraged - AS
if isinstance(evaluator, str):
self.evaluator = EVALUATORS[evaluator]
else:
self.evaluator = evaluator

def update(self, X, y_true=None, y_pred=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/menelaus/test_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_stream_ensemble_1():
step3 = STEPD(window_size=2)
se = StreamingEnsemble(
detectors={"s1": step1, "s2": step2, "s3": step3},
evaluator=EVALUATORS["simple-majority"]
evaluator="simple-majority"
)
df = pd.DataFrame({"a": [0,0], "b": [0,0], "c": [0,0]})
se.update(X=df.iloc[[0]], y_true=0, y_pred=0)
Expand Down

0 comments on commit d4d45de

Please sign in to comment.