Skip to content

Commit

Permalink
Fix model info to work with pipeline (#405)
Browse files Browse the repository at this point in the history
* Fix model info to work with pipeline

* Organize imports

* Fix pylint blank line
  • Loading branch information
matanper committed Jan 2, 2022
1 parent eb7e6bb commit df7ad4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
11 changes: 5 additions & 6 deletions deepchecks/checks/overview/model_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from deepchecks import ModelOnlyBaseCheck, CheckResult
from deepchecks.utils.validation import model_type_validation
from deepchecks.utils.model import get_model_of_pipeline


__all__ = ['ModelInfo']
Expand All @@ -31,13 +32,11 @@ def run(self, model: BaseEstimator) -> CheckResult:
Returns:
CheckResult: value is dictionary in format {type: <model_type>, params: <model_params_dict>}
"""
return self._model_info(model)

def _model_info(self, model: BaseEstimator):
model_type_validation(model)
model_type = type(model).__name__
model_params = model.get_params()
default_params = type(model)().get_params()
estimator = get_model_of_pipeline(model)
model_type = type(estimator).__name__
model_params = estimator.get_params()
default_params = type(estimator)().get_params()

# Create dataframe to show
model_param_df = pd.DataFrame(model_params.items(), columns=['Parameter', 'Value'])
Expand Down
13 changes: 13 additions & 0 deletions tests/checks/overview/model_info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#
"""Tests for Model Info."""
from hamcrest import assert_that, has_entries, calling, raises
from sklearn.impute import SimpleImputer
from sklearn.pipeline import Pipeline

from deepchecks.checks.overview.model_info import ModelInfo
from deepchecks.errors import DeepchecksValueError

Expand Down Expand Up @@ -38,6 +41,16 @@ def test_model_info_object(iris_adaboost):
assert_model_result(result)


def test_model_info_pipeline(iris_adaboost):
# Arrange
simple_pipeline = Pipeline([('nan_handling', SimpleImputer(strategy='most_frequent')),
('adaboost', iris_adaboost)])
# Act
result = ModelInfo().run(simple_pipeline)
# Assert
assert_model_result(result)


def test_model_info_wrong_input():
# Act
assert_that(calling(ModelInfo().run).with_args('some string'),
Expand Down

0 comments on commit df7ad4e

Please sign in to comment.