midlearn.MIDExplainer
- class midlearn.MIDExplainer(estimator, target_classes: str | list[str] | None = None, params_main: int | None = None, params_inter: int | None = None, penalty: float = 0, link: str | None = None, kernel_type: int | list[int] = 1, encoding_frames: dict = {}, model_terms: str | list[str] | None = None, singular_ok: bool = False, mode: int = 1, method: int | None = None, centering_penalty: float = 1000000.0, na_action: str | None = 'na.omit', verbosity: int = 1, encoding_digits: int | None = 3, use_catchall: bool = False, catchall: str = '(others)', max_nelements: int | None = 1000000000.0, nil: float = 1e-07, tol: float = 1e-07, **kwargs)[source]
Surrogate Maximium Interpretation Decomposition explainer.
- __init__(estimator, target_classes: str | list[str] | None = None, params_main: int | None = None, params_inter: int | None = None, penalty: float = 0, link: str | None = None, kernel_type: int | list[int] = 1, encoding_frames: dict = {}, model_terms: str | list[str] | None = None, singular_ok: bool = False, mode: int = 1, method: int | None = None, centering_penalty: float = 1000000.0, na_action: str | None = 'na.omit', verbosity: int = 1, encoding_digits: int | None = 3, use_catchall: bool = False, catchall: str = '(others)', max_nelements: int | None = 1000000000.0, nil: float = 1e-07, tol: float = 1e-07, **kwargs)[source]
Create a surrogate MID model to explain a pre-trained black-box model. estimator : scikit-learn compatible estimator
The pre-trained black-box model to be explained.
- target_classesstr or list[str], optional
Specifies the target class or classes for which the probability is to be explained. If a list is provided, the sum of probabilities is used. This parameter is ignored if the estimator is not a classifier.
params_main : int or None, optional params_inter : int or None, optional penalty : float, optional link : str, optional kernel_type : int or list[int], optional encoding_frames : dict, optional model_terms : str or list[str], optional singular_ok : bool, optional mode : int, optional method : int, optional centering_penalty : float, optional na_action : str, optional verbosity : int, optional encoding_digits : int, optional use_catchall : bool, optional catchall : str, optional max_nelements : int, optional nil : float, optional tol : float, optional
Arguments passed to the parent MIDRegressor constructor. See the MIDRegressor documentation for details.
- **kwargsdict
Additional keyword arguments passed to midr::interpret(). See MIDRegressor documentation.
Methods
__init__(estimator[, target_classes, ...])Create a surrogate MID model to explain a pre-trained black-box model. estimator : scikit-learn compatible estimator The pre-trained black-box model to be explained. target_classes : str or list[str], optional Specifies the target class or classes for which the probability is to be explained. If a list is provided, the sum of probabilities is used. This parameter is ignored if the estimator is not a classifier.
breakdown(**kwargs)Create MIDBreakdown object from the fitted estimator.
conditional(variable, **kwargs)Create MIDConditional object from the fitted estimator.
effect(term, x[, y])Evaluate a single MID component function for new data.
fidelity_score(X[, y, sample_weight])Calculate the fidelity of the surrogate model.
fit(X[, y, sample_weight])Fit the surrogate MID model to the predictions of the estimator on X.
get_metadata_routing()Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
importance(**kwargs)Create MIDImportance object from the fitted estimator.
interactions(term)Extract a pd.DataFrame representing the interaction of the specified 'term'.
main_effects(term)Extract a pd.DataFrame representing the main effect of the specified 'term'.
plot(term[, style, theme, intercept, ...])Visualize the estimated main or interaction effect of a fitted MID model with plotnine.
predict(X)Predict target values for new data X using the fitted MID model.
predict_terms(X)Predict the contribution of each term for new data X.
r_predict(X[, output_type, terms])A low-level method to call the R predict.mid function.
score(X, y[, sample_weight])Return coefficient of determination on test data.
set_fit_request(*[, sample_weight])Configure whether metadata should be requested to be passed to the
fitmethod.set_params(**params)Set the parameters of this estimator.
set_score_request(*[, sample_weight])Configure whether metadata should be requested to be passed to the
scoremethod.terms(**kwargs)Extract term labels from the fitted model.
Attributes
fitted_matrixA pandas DataFrame showing the breakdown of the fitted values into the effects of the component functions.
fitted_valuesA NumPy array of the fitted values.
interceptThe intercept of the fitted model.
ratioThe ratio of the sum of squared error between the target model predictions and the fitted values, to the sum of squared deviations of the target model predictions.
residualsA NumPy array of the working residuals.
weightsSample weights used to fit the model.