How to use the fairlearn.exceptions.NotFittedException function in fairlearn

To help you get started, we’ve selected a few fairlearn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fairlearn / fairlearn / test / unit / reductions / grid_search / test_grid_search_arguments.py View on Github external
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]
github fairlearn / fairlearn / test / unit / reductions / grid_search / test_grid_search_arguments.py View on Github external
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]
github fairlearn / fairlearn / fairlearn / postprocessing / _threshold_optimizer.py View on Github external
def _validate_post_processed_predictor_is_fitted(self):
        if not self._post_processed_predictor_by_sensitive_feature:
            raise NotFittedException(PREDICT_BEFORE_FIT_ERROR_MESSAGE)
github fairlearn / fairlearn / fairlearn / reductions / _grid_search / grid_search.py View on Github external
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)
github fairlearn / fairlearn / fairlearn / reductions / _grid_search / grid_search.py View on Github external
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)