BdeRegressor#
- class bde.BdeRegressor(n_members: int = 2, hidden_layers: list[int] | None = None, seed: int = 0, loss: BaseLoss | None = None, activation: str = 'relu', epochs: int = 20, patience: int | None = None, validation_split: float = 0.15, n_samples: int = 10, warmup_steps: int = 50, lr: float = 0.001, weight_decay: float = 0.0001, n_thinning: int = 2, desired_energy_var_start: float = 0.5, desired_energy_var_end: float = 0.1, step_size_init: float | None = None, prior_family: str | PriorDist = 'standardnormal', prior_kwargs: dict[str, Any] | None = None)#
Regression-friendly wrapper exposing scikit-learn style API.
Methods
fit(x, y)Fit the regression ensemble on the provided dataset.
Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
history()Return training history from the builder.
predict(x[, mean_and_std, ...])Predict regression targets with optional uncertainty summaries.
score(X, y[, sample_weight])Return coefficient of determination on test data.
set_fit_request(*[, x])Configure whether metadata should be requested to be passed to the
fitmethod.set_params(**params)Set the parameters of this estimator.
set_predict_request(*[, credible_intervals, ...])Configure whether metadata should be requested to be passed to the
predictmethod.set_score_request(*[, sample_weight])Configure whether metadata should be requested to be passed to the
scoremethod.- __init__(n_members: int = 2, hidden_layers: list[int] | None = None, seed: int = 0, loss: BaseLoss | None = None, activation: str = 'relu', epochs: int = 20, patience: int | None = None, validation_split: float = 0.15, n_samples: int = 10, warmup_steps: int = 50, lr: float = 0.001, weight_decay: float = 0.0001, n_thinning: int = 2, desired_energy_var_start: float = 0.5, desired_energy_var_end: float = 0.1, step_size_init: float | None = None, prior_family: str | PriorDist = 'standardnormal', prior_kwargs: dict[str, Any] | None = None)#
Initialise the regressor with architecture, optimisation, and sampling settings.
- Parameters:
- n_membersint, default=2
Number of deterministic networks in the ensemble.
- hidden_layerslist[int] | None, default= None
Hidden layer widths; defaults to
[4, 4]internally whenNone.- seedint, default=0
Shared PRNG seed for member initialisation and sampling.
- lossBaseLoss | None
Custom training loss; defaults to
bde.loss.GaussianNLL.- activationstr, default=’relu’
Activation function applied to each hidden layer.
- epochsint, default=20
Maximum training epochs during the deterministic phase.
- patienceint | None, optional
Early-stopping patience measured in epochs;
Nonedisables it.- validation_splitfloat, default=0.15
Fraction of data reserved for validation when early stopping is enabled. Must lie in (0, 1); when
None, all data is used and early stopping is skipped.- n_samplesint, default=10
Posterior samples retained for each ensemble member.
- warmup_stepsint, default=50
Number of warm-up iterations for the MCMC sampler.
- lrfloat, default=1e-3
Learning rate for the Adam optimiser used in pre-sampling training.
- weight_decay: float
Weight decay parameter for the AdamW optimiser applied during member training.
- n_thinningint, default=2
Thinning interval applied to posterior samples.
- desired_energy_var_startfloat, default=0.5
Target energy variance at the start of warm-up.
- desired_energy_var_endfloat, default=0.1
Target energy variance at the end of warm-up.
- step_size_initfloat | None, optional
Override for the sampler’s initial step size; falls back to
lr.- prior_familystr or PriorDist
Prior distribution for network weights; accepts a
PriorDistenum or string key. Defaults to"standardnormal".- prior_kwargsdict[str, Any] | None
Optional keyword arguments forwarded to the chosen
prior_family(e.g.{"scale": 0.1}for a wider or narrower Normal or Laplace).
- fit(x: Array | ndarray | bool_ | number | bool | int | float | complex, y: Array | ndarray | bool_ | number | bool | int | float | complex)#
Fit the regression ensemble on the provided dataset.
- Parameters:
- xArrayLike
Feature matrix of shape (n_samples, n_features).
- yArrayLike
Continuous targets shaped (n_samples,) or (n_samples, 1).
- Returns:
- BdeRegressor
The fitted estimator instance.
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating routing information.
- get_params(deep=True)#
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- history()#
Return training history from the builder.
- Returns:
- dict[str, dict[str, list[float]]]
Dictionary mapping member names to their training and validation loss histories.
- predict(x: Array | ndarray | bool_ | number | bool | int | float | complex, mean_and_std: bool = False, credible_intervals: list[float] | None = None, raw: bool = False)#
Predict regression targets with optional uncertainty summaries.
- Parameters:
- xArrayLike
Feature matrix of shape (n_samples, n_features).
- mean_and_stdbool, default=False
When
True, return a tuple(mean, std)where both arrays have shape(n_samples,)andstdcombines aleatoric and epistemic uncertainty.- credible_intervalslist[float] | None, default=None
Quantile levels in (0, 1) used to summarise the predictive distribution. When not
Noneandmean_and_stdisFalse, the method returns(mean, quantiles)wheremeanhas shape(n_samples,)andquantileshas shape(Q, n_samples)with one row per requested level. Note that the values are quantiles, not closed intervals; for an 80% interval you would typically pass[0.1, 0.9]and interpret the two returned quantile curves as lower and upper bounds.- rawbool, default=False
When
True, ignore other flags and return the raw ensemble outputs with shape(n_members, n_samples_draws, n_samples, 2), corresponding to per-member, per-draw mean and scale parameters.
- Returns:
- ArrayLike | tuple[jax.Array, jax.Array]
If
rawisTrue, the raw tensor described above.If
mean_and_stdisTrue, a tuple(mean, std).If
credible_intervalsis provided, a tuple(mean, quantiles).Otherwise, the predictive mean
(n_samples,).
- score(X, y, sample_weight=None)#
Return coefficient of determination on test data.
The coefficient of determination, \(R^2\), is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares
((y_true - y_pred)** 2).sum()and \(v\) is the total sum of squares((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value ofy, disregarding the input features, would get a \(R^2\) score of 0.0.- Parameters:
- Xarray-like of shape (n_samples, n_features)
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape
(n_samples, n_samples_fitted), wheren_samples_fittedis the number of samples used in the fitting for the estimator.- yarray-like of shape (n_samples,) or (n_samples, n_outputs)
True values for
X.- sample_weightarray-like of shape (n_samples,), default=None
Sample weights.
- Returns:
- scorefloat
\(R^2\) of
self.predict(X)w.r.t.y.
Notes
The \(R^2\) score used when calling
scoreon a regressor usesmultioutput='uniform_average'from version 0.23 to keep consistent with default value ofr2_score(). This influences thescoremethod of all the multioutput regressors (except forMultiOutputRegressor).
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') BdeRegressor#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif 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.Added in version 1.3.
- Parameters:
- xstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
xparameter infit.
- Returns:
- selfobject
The updated object.
- set_params(**params)#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline). The latter have parameters of the form<component>__<parameter>so that it’s possible to update each component of a nested object.- Parameters:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.
- set_predict_request(*, credible_intervals: bool | None | str = '$UNCHANGED$', mean_and_std: bool | None | str = '$UNCHANGED$', raw: bool | None | str = '$UNCHANGED$', x: bool | None | str = '$UNCHANGED$') BdeRegressor#
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif 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.Added in version 1.3.
- Parameters:
- credible_intervalsstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
credible_intervalsparameter inpredict.- mean_and_stdstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
mean_and_stdparameter inpredict.- rawstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
rawparameter inpredict.- xstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
xparameter inpredict.
- Returns:
- selfobject
The updated object.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') BdeRegressor#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif 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.Added in version 1.3.
- Parameters:
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
- Returns:
- selfobject
The updated object.