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:
- X
ndarray
ofshape
(n_samples
,n_features
) Training data.
- y
ndarray
ofshape
(n_samples,) Target values. Will be cast to X’s dtype if necessary.
- sample_weight
ndarray
ofshape
(n_samples,), default=None Individual weights for each sample.
New in version 0.20: parameter sample_weight support to BayesianRidge.
- X
- Returns:
- self
object
Returns the instance itself.
- self
- 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
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.
- 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
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.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.
- 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
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.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.
- 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:
- X
ndarray
ofshape
(n_samples
,n_features
) Training data.
- y
ndarray
ofshape
(n_samples,) Target values. Will be cast to X’s dtype if necessary.
- sample_weight
ndarray
ofshape
(n_samples,), default=None Individual weights for each sample.
New in version 0.20: parameter sample_weight support to BayesianRidge.
- X
- Returns:
- self
object
Returns the instance itself.
- self
- 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
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.
- 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
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.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.
- 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
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.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.