コード例 #1
0
    def test_predict_values(self, estimator, explainer_type, X_y):
        X, y = X_y
        X_test = X[:1, :]
        regressor = ExplainableRegressor(estimator, explainer_type)
        regressor_predictions = regressor.fit(X, y).predict(X_test)

        cloned_estimator = clone(estimator)
        estimator_predictions = cloned_estimator.fit(X, y).predict(X_test)

        assert regressor_predictions.shape == estimator_predictions.shape
        assert regressor_predictions.shape[0] == len(regressor.explanations_)
コード例 #2
0
    def test_fit_values(self, estimator, explainer_type, X_y):
        X, y = X_y
        regressor = ExplainableRegressor(estimator, explainer_type)
        regressor.fit(X, y)

        cloned_estimator = clone(estimator)
        cloned_estimator.fit(X, y)

        estimator_fit_attributes = self._get_fit_attributes(
            regressor.estimator)
        cloned_estimator_fit_attributes = self._get_fit_attributes(
            cloned_estimator)

        np.testing.assert_array_equal(estimator_fit_attributes,
                                      cloned_estimator_fit_attributes)
コード例 #3
0
ファイル: gar.py プロジェクト: niko992/giotto-time
def initialize_estimator(
    estimator: RegressorMixin, explainer_type: Optional[str]
) -> RegressorMixin:
    if explainer_type is None:
        return estimator
    else:
        return ExplainableRegressor(estimator, explainer_type)
コード例 #4
0
 def test_error_predict_not_fitted(self, estimator, explainer_type, X):
     regressor = ExplainableRegressor(estimator, explainer_type)
     with pytest.raises(NotFittedError):
         regressor.predict(X)
コード例 #5
0
 def test_constructor_bad_regressor(self, bad_estimator, explainer_type):
     with pytest.raises(TypeError):
         ExplainableRegressor(bad_estimator, explainer_type)
コード例 #6
0
 def test_constructor_bad_explainer(self, estimator):
     with pytest.raises(ValueError):
         ExplainableRegressor(estimator, "bad")
コード例 #7
0
 def test_constructor(self, estimator, explainer_type):
     regressor = ExplainableRegressor(estimator, explainer_type)
     if explainer_type == "lime":
         assert isinstance(regressor.explainer, _LimeExplainer)
     elif explainer_type == "shap":
         assert isinstance(regressor.explainer, _ShapExplainer)