Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add is_fitted function to decider #140

Merged
merged 3 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion proglearn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ def predict(self, X):
Input data matrix.
"""
pass

@abc.abstractmethod
def is_fitted(self):
"""
Indicates whether the decider is fitted.

Parameters
----------
None
"""
pass


class ClassificationDecider(BaseDecider):
Expand Down Expand Up @@ -229,4 +240,4 @@ def predict_proba(self, X, task_id):
task_id : obj
The task on which you are interested in estimating posteriors.
"""
pass
pass
17 changes: 17 additions & 0 deletions proglearn/deciders.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SimpleAverage(ClassificationDecider):

def __init__(self, classes=[]):
self.classes = classes
self._is_fitted = False

def fit(
self,
Expand All @@ -43,6 +44,8 @@ def fit(
self.classes = np.array(self.classes)
self.transformer_id_to_transformers = transformer_id_to_transformers
self.transformer_id_to_voters = transformer_id_to_voters

self._is_fitted = True
return self

def predict_proba(self, X, transformer_ids=None):
Expand All @@ -67,5 +70,19 @@ def predict_proba(self, X, transformer_ids=None):
return np.mean(vote_per_transformer_id, axis=0)

def predict(self, X, transformer_ids=None):
if not self.is_fitted():
msg = (
"This %(name)s instance is not fitted yet. Call 'fit' with "
"appropriate arguments before using this decider."
)
raise NotFittedError(msg % {"name": type(self).__name__})

vote_overall = self.predict_proba(X, transformer_ids=transformer_ids)
return self.classes[np.argmax(vote_overall, axis=1)]

def is_fitted(self):
"""
Doc strings here.
"""

return self._is_fitted