-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new method add_permutation_importances to the Card class that adds a plot of sklearn.inspection.permutation_importance to the model card. Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com> Co-authored-by: Benjamin Bossan <BenjaminBossan@users.noreply.github.com>
- Loading branch information
1 parent
9407ba7
commit 81558aa
Showing
9 changed files
with
240 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from importlib import import_module | ||
|
||
|
||
def import_or_raise(module, feature_name): | ||
"""Raise error if a given library is not present in the environment. | ||
Parameters | ||
---------- | ||
module: str | ||
Name of the module. | ||
feature_name: str | ||
Name of the feature module is required for. | ||
Raises | ||
------ | ||
ModuleNotFoundError | ||
Is raised if a given module is not present in the environment | ||
""" | ||
try: | ||
module = import_module(module) | ||
except ImportError as e: | ||
package = module.split(".")[0] | ||
raise ModuleNotFoundError( | ||
f"{feature_name.capitalize()} requires {package} to be installed. In order" | ||
f" to use {feature_name}, you need to install the package in your current" | ||
" python environment." | ||
) from e | ||
return module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import pytest | ||
|
||
from skops.utils.importutils import import_or_raise | ||
|
||
|
||
@pytest.mark.usefixtures("matplotlib_not_installed") | ||
def test_import_or_raise(): | ||
with pytest.raises( | ||
ModuleNotFoundError, | ||
match=( | ||
"Permutation importance requires matplotlib to be installed. In order" | ||
" to use permutation importance, you need to install the package in" | ||
" your current python environment." | ||
), | ||
): | ||
import_or_raise("matplotlib", "permutation importance") |