Skip to content

Commit

Permalink
allow estimator_type in [None, 'transformer'] for PipelineElement wit…
Browse files Browse the repository at this point in the history
…hout predict method
  • Loading branch information
lucasplagwitz committed Sep 23, 2020
1 parent 71f70ab commit 5d38769
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions photonai/base/photon_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,21 @@ def random_state(self, random_state):

@property
def _estimator_type(self):
if hasattr(self.base_element, '_estimator_type'):
est_type = getattr(self.base_element, '_estimator_type')
if est_type is not 'classifier' and est_type is not 'regressor':
raise NotImplementedError("Currently, we only support type classifier or regressor. Is {}.".format(est_type))
# estimator_type obligation for estimators, is ignored if a transformer is given
# prevention of misuse through predict test (predict method available <=> Estimator).
est_type = getattr(self.base_element, '_estimator_type', None)
if est_type in [None, 'transformer']:
if hasattr(self.base_element, 'predict'):
raise NotImplementedError("Element has predict() method but does not specify whether it is a regressor"
" or classifier. Remember to inherit from ClassifierMixin or RegressorMixin.")
return None
else:
if est_type not in ['classifier', 'regressor']:
raise NotImplementedError("Currently, we only support type classifier or regressor."
" Is {}.".format(est_type))
if not hasattr(self.base_element, 'predict'):
raise NotImplementedError("Estimator does not implement predict() method.")
return est_type
else:
if hasattr(self.base_element, 'predict'):
raise NotImplementedError("Element has predict() method but does not specify whether it is a regressor "
"or classifier. Remember to inherit from ClassifierMixin or RegressorMixin.")
else:
return None

# this is only here because everything inherits from PipelineElement.
def __iadd__(self, pipe_element):
Expand Down

0 comments on commit 5d38769

Please sign in to comment.