Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap call to scikit-learn's partial dependence method in a try/finally block #1232

Merged
merged 3 commits into from Sep 28, 2020

Conversation

angela97lin
Copy link
Contributor

From @dsherry's comment in #1150, wrap call to scikit-learn's partial dependence method in a try/finally block so that we still delete the set attributes even if call to scikit-learn's partial dependence method fails or errors out.

@angela97lin angela97lin self-assigned this Sep 28, 2020
@codecov
Copy link

codecov bot commented Sep 28, 2020

Codecov Report

Merging #1232 into main will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1232   +/-   ##
=======================================
  Coverage   99.92%   99.92%           
=======================================
  Files         196      196           
  Lines       12193    12206   +13     
=======================================
+ Hits        12184    12197   +13     
  Misses          9        9           
Impacted Files Coverage Δ
evalml/model_understanding/graphs.py 100.00% <100.00%> (ø)
...lml/tests/model_understanding_tests/test_graphs.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9998cf8...a141659. Read the comment docs.

Copy link
Contributor

@jeremyliweishih jeremyliweishih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -689,6 +689,20 @@ def test_partial_dependence_problem_types(problem_type, X_y_binary, X_y_multi, X
pipeline.feature_importances_


@patch('evalml.model_understanding.graphs.sk_partial_dependence')
def test_partial_dependence_error_still_deletes_attributes(mock_part_dep, X_y_binary, logistic_regression_binary_pipeline_class):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test!

Copy link
Contributor

@bchen1116 bchen1116 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@angela97lin I think this looks great!

# Delete scikit-learn attributes that were temporarily set
del pipeline._estimator_type
del pipeline.feature_importances_
try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have to repeat this pattern in the future, it'd be cool to use a context manager!

@angela97lin angela97lin added this to the September 2020 milestone Sep 28, 2020
@angela97lin angela97lin merged commit 20af560 into main Sep 28, 2020
@angela97lin angela97lin deleted the ange_partial_dependence_finally branch September 28, 2020 18:14
@angela97lin angela97lin mentioned this pull request Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants