Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_no_predict_proba_before_fit(self):
gs = GridSearch(self.estimator, self.disparity_criterion)
X, _, _ = self._quick_data()
message = str("Must call fit before attempting to make predictions")
with pytest.raises(NotFittedException) as execInfo:
gs.predict_proba(X)
assert message == execInfo.value.args[0]
def test_no_predict_before_fit(self):
gs = GridSearch(self.estimator, self.disparity_criterion)
X, _, _ = self._quick_data()
message = str("Must call fit before attempting to make predictions")
with pytest.raises(NotFittedException) as execInfo:
gs.predict(X)
assert message == execInfo.value.args[0]
def _validate_post_processed_predictor_is_fitted(self):
if not self._post_processed_predictor_by_sensitive_feature:
raise NotFittedException(PREDICT_BEFORE_FIT_ERROR_MESSAGE)
def predict_proba(self, X):
"""Provide the result of :code:`predict_proba` from the best model found by the grid search.
The underlying estimator must support :code:`predict_proba` for this
to work.
:param X: The data for which predictions are required
:type X: Array
"""
if self.best_result is None:
raise NotFittedException(_NO_PREDICT_BEFORE_FIT)
return self.best_result.predictor.predict_proba(X)
def predict(self, X):
"""Provide a prediction for the given input data based on the best model found by the grid search.
:param X: The data for which predictions are required
:type X: Array
:return: The prediction. If X represents the data for a single example
the result will be a scalar. Otherwise the result will be an
:rtype: Scalar or array
"""
if self.best_result is None:
raise NotFittedException(_NO_PREDICT_BEFORE_FIT)
return self.best_result.predictor.predict(X)