xai_compare.factories.factory
Classes
|
A class for creating classes or instances of various comparison techniques based on the given explainers. |
|
A class for creating instances of various explainer types based on the given model and data. |
- class xai_compare.factories.factory.ComparisonFactory(model, data: DataFrame, target: DataFrame | Series | ndarray, mode: str = 'regression', random_state: int = 42, verbose: bool = True, threshold: float = 0.2, metric: str | None = None, n_splits: int = 5, default_explainers: List[str] = ['shap', 'lime', 'permutations'], custom_explainer: Type[Explainer] | List[Type[Explainer]] | None = None)
A class for creating classes or instances of various comparison techniques based on the given explainers.
This class simplifies the process of instantiating different types of comparison techniques by providing a common interface to specify the necessary training and testing datasets along with the model.
- create(comparison_type: <module 'string' from '/home/docs/.asdf/installs/python/3.10.14/lib/python3.10/string.py'>)
Creates and returns a comparison object based on the specified type.
This method allows for dynamic creation of different types of comparison objects based on a predefined string identifier. If the model is not set, it returns the class of the comparison for manual instantiation.
- Attributes:
- comparison_type (str):
A string identifier for the comparison type. Valid options are “feature_selection”, “consistency”.
- Returns:
- comparison.Comparison:
An instance or class of the requested comparison type with the provided model and data.
- Raises:
- ValueError:
If the comparison_type is not recognized or unsupported.
- class xai_compare.factories.factory.ExplainerFactory(model: Any | None = None, X_train: DataFrame | None = None, X_test: DataFrame | None = None, y_train: DataFrame | Series | ndarray | None = None, y_test: DataFrame | Series | ndarray | None = None, mode: str = 'regression')
A class for creating instances of various explainer types based on the given model and data.
This class simplifies the process of instantiating different types of explainers by providing a common interface to specify the necessary training and testing datasets along with the model.
- Attributes:
- model (Any):
The machine learning model to be explained.
- X_train (pd.DataFrame):
Training features dataset.
- X_test (pd.DataFrame):
Testing features dataset.
- y_train (Union[pd.DataFrame, pd.Series, np.ndarray]):
Training target dataset.
- y_test (Union[pd.DataFrame, pd.Series, np.ndarray]):
Testing target dataset.
- mode (str):
Mode of operation, specifies if the model is for ‘regression’ or ‘classification’.
- create(explainer_type: <module 'string' from '/home/docs/.asdf/installs/python/3.10.14/lib/python3.10/string.py'>) Explainer
Creates and returns an explainer object based on the specified type.
This method allows for dynamic creation of different types of explainer objects based on a predefined string identifier. If the model is not set, it returns the class of the explainer for manual instantiation.
- Attributes:
- explainer_type (str):
A string identifier for the explainer type. Valid options are “shap”, “lime”, “permutations”.
- Returns:
- Explainer:
An instance of the requested explainer type with the provided model and data.
- Raises:
- ValueError:
If the explainer_type is not recognized or unsupported.