-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d91815
commit 4819fad
Showing
7 changed files
with
42 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,46 @@ | ||
from typing import Optional | ||
import pandas as pd | ||
from explainerdashboard import RegressionExplainer | ||
|
||
from pipeline_lib.core import DataContainer | ||
|
||
from .base import PipelineStep | ||
from pipeline_lib.core.steps import PipelineStep | ||
|
||
|
||
class ExplainerDashboardStep(PipelineStep): | ||
"""Explainer Dashboard.""" | ||
|
||
def __init__(self, config: Optional[dict] = None) -> None: | ||
"""Initialize ExplainerDashboardStep.""" | ||
super().__init__(config=config) | ||
"""Scale the target using Quantile Transformer.""" | ||
def __init__( | ||
self, | ||
max_samples: int = 1000, | ||
) -> None: | ||
self.init_logger() | ||
self.max_samples = max_samples | ||
|
||
def execute(self, data: DataContainer) -> DataContainer: | ||
"""Execute the step.""" | ||
self.logger.info("Creating explainer dashboard.") | ||
self.logger.debug("Starting explainer dashboard") | ||
|
||
model = data.get(DataContainer.MODEL) | ||
if model is None: | ||
raise ValueError("Model not found in data container.") | ||
|
||
target = data.get(DataContainer.TARGET) | ||
if target is None: | ||
raise ValueError("Target column not found in any parameter.") | ||
|
||
df = data.get(DataContainer.CLEAN) | ||
|
||
if len(df) > self.max_samples: | ||
# Randomly sample a subset of data points if the dataset is larger than max_samples | ||
self.logger.info(f"Sampling {self.max_samples} data points from the dataset.") | ||
df = df.sample(n=self.max_samples, random_state=42) | ||
|
||
drop_columns = data.get("drop_columns") | ||
if drop_columns: | ||
df = df.drop(columns=drop_columns) | ||
|
||
X_test = df.drop(columns=[target]) | ||
y_test = df[target] | ||
|
||
explainer = RegressionExplainer(model, X_test, y_test,) | ||
|
||
data[DataContainer.EXPLAINER] = explainer | ||
|
||
return data |
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
from .explainer_dashboard import XGBoostExplainerDashboardStep # noqa: F401 | ||
from .fit_model import XGBoostFitModelStep # noqa: F401 | ||
from .predict import XGBoostPredictStep # noqa: F401 |
40 changes: 0 additions & 40 deletions
40
pipeline_lib/implementation/tabular/xgboost/explainer_dashboard.py
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