BayLIME extension (visualime.baylime)

BayLIME (Bayesian Local Interpretable Model-Agnostic Explanations) [1] is an extension of LIME [2] that exploits prior knowledge and Bayesian reasoning.

[1] Zhao et al. (2021): BayLIME: Bayesian Local Interpretable Model-Agnostic Explanations. arXiv:2012.03058

[2] Ribeiro et al. (2016): “Why Should I Trust You?”: Explaining the Predictions of Any Classifier. arXiv:1602.04938

class visualime.baylime.BayesianRidgeFixedLambda(*, epsilon: float = 1e-06, large_number: float = 1000000000.0, **kwargs)[source]

Bases: BayesianRidge

BayesianRidge model with fixed parameter lambda. This is equivalent to the “partial informative priors” option in the BayLIME framework.

The value for lambda_init will be treated as a constant. The parameter epsilon specifies the maximum amount of change allowed for lambda. A warning will be issued if this amount is exceeded. To reduce the amount of change in lambda, increase large_number.

See the documentation for sklearn.linear_model.BayesianRidge() for a list of available parameters.

Methods

fit(X, y[, sample_weight])

Fit the model.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict(X[, return_std])

Predict using the linear model.

score(X, y[, sample_weight])

Return the coefficient of determination of the prediction.

set_fit_request(*[, sample_weight])

Request metadata passed to the fit method.

set_params(**params)

Set the parameters of this estimator.

set_predict_request(*[, return_std])

Request metadata passed to the predict method.

set_score_request(*[, sample_weight])

Request metadata passed to the score method.

fit(X, y, sample_weight=None)[source]

Fit the model.

Parameters:
Xndarray of shape (n_samples, n_features)

Training data.

yndarray of shape (n_samples,)

Target values. Will be cast to X’s dtype if necessary.

sample_weightndarray of shape (n_samples,), default=None

Individual weights for each sample.

New in version 0.20: parameter sample_weight support to BayesianRidge.

Returns:
selfobject

Returns the instance itself.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') BayesianRidgeFixedLambda

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

set_predict_request(*, return_std: bool | None | str = '$UNCHANGED$') BayesianRidgeFixedLambda

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
return_stdstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for return_std parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') BayesianRidgeFixedLambda

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class visualime.baylime.BayesianRidgeFixedAlphaLambda(*, epsilon: float = 1e-06, large_number: float = 1000000000.0, **kwargs)[source]

Bases: BayesianRidge

BayesianRidge model with fixed parameters alpha and lambda. This is equivalent to the “full informative priors” option in the BayLIME framework.

The values for alpha_init and lambda_init will be treated as constants.

The parameter epsilon specifies the maximum amount of change allowed for alpha and lambda. A warning will be issued if this amount is exceeded. To reduce the amount of change, increase large_number.

See the documentation for sklearn.linear_model.BayesianRidge() for a list of available parameters.

Methods

fit(X, y[, sample_weight])

Fit the model.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict(X[, return_std])

Predict using the linear model.

score(X, y[, sample_weight])

Return the coefficient of determination of the prediction.

set_fit_request(*[, sample_weight])

Request metadata passed to the fit method.

set_params(**params)

Set the parameters of this estimator.

set_predict_request(*[, return_std])

Request metadata passed to the predict method.

set_score_request(*[, sample_weight])

Request metadata passed to the score method.

fit(X, y, sample_weight=None)[source]

Fit the model.

Parameters:
Xndarray of shape (n_samples, n_features)

Training data.

yndarray of shape (n_samples,)

Target values. Will be cast to X’s dtype if necessary.

sample_weightndarray of shape (n_samples,), default=None

Individual weights for each sample.

New in version 0.20: parameter sample_weight support to BayesianRidge.

Returns:
selfobject

Returns the instance itself.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') BayesianRidgeFixedAlphaLambda

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

set_predict_request(*, return_std: bool | None | str = '$UNCHANGED$') BayesianRidgeFixedAlphaLambda

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
return_stdstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for return_std parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') BayesianRidgeFixedAlphaLambda

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.