-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renaming of "diagnostics" package into "insights", Addition of Insigh…
…t and SHAPInsight classes, refactoring of SHAP functions into SHAPInsight class.
- Loading branch information
Showing
16 changed files
with
599 additions
and
438 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 was deleted.
Oops, something went wrong.
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,16 @@ | ||
"""Optional import for insight subpackage.""" | ||
|
||
from baybe.exceptions import OptionalImportError | ||
|
||
try: | ||
import shap | ||
except ModuleNotFoundError as ex: | ||
raise OptionalImportError( | ||
"Explainer functionality is unavailable because 'insights' is not installed." | ||
" Consider installing BayBE with 'insights' dependency, e.g. via " | ||
"`pip install baybe[insights]`." | ||
) from ex | ||
|
||
__all__ = [ | ||
"shap", | ||
] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
"""Baybe insights (optional).""" | ||
|
||
from baybe._optional.info import INSIGHTS_INSTALLED | ||
|
||
if INSIGHTS_INSTALLED: | ||
from baybe.insights.base import Insight | ||
from baybe.insights.shap import SHAPInsight | ||
|
||
__all__ = [ | ||
"SHAPInsight", | ||
"Insight", | ||
] |
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,45 @@ | ||
"""Base class for all insights.""" | ||
|
||
from abc import ABC | ||
|
||
import pandas as pd | ||
|
||
from baybe import Campaign | ||
from baybe._optional.info import INSIGHTS_INSTALLED | ||
from baybe.objectives.base import Objective | ||
from baybe.recommenders.pure.bayesian.base import BayesianRecommender | ||
from baybe.searchspace import SearchSpace | ||
|
||
if INSIGHTS_INSTALLED: | ||
pass | ||
|
||
|
||
class Insight(ABC): | ||
"""Base class for all insights.""" | ||
|
||
def __init__(self, surrogate): | ||
self.surrogate = surrogate | ||
|
||
@classmethod | ||
def from_campaign(cls, campaign: Campaign): | ||
"""Create an insight from a campaign.""" | ||
return cls(campaign.get_surrogate()) | ||
|
||
@classmethod | ||
def from_recommender( | ||
cls, | ||
recommender: BayesianRecommender, | ||
searchspace: SearchSpace, | ||
objective: Objective, | ||
bg_data: pd.DataFrame, | ||
): | ||
"""Create an insight from a recommender.""" | ||
if not hasattr(recommender, "get_surrogate"): | ||
raise ValueError( | ||
"The provided recommender does not provide a surrogate model." | ||
) | ||
surrogate_model = recommender.get_surrogate(searchspace, objective, bg_data) | ||
|
||
return cls( | ||
surrogate_model, | ||
) |
Oops, something went wrong.