BayesianRidge
Bayesian ridge regression.
Fit a Bayesian ridge model. See the Notes section for details on this implementation and the optimization of the regularization parameters lambda (precision of the weights) and alpha (precision of the noise).
Read more in the User Guide.
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new BayesianRidge(opts?: object): BayesianRidge;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.alpha_1? | number | Hyper-parameter : shape parameter for the Gamma distribution prior over the alpha parameter. Default Value 0.000001 |
opts.alpha_2? | number | Hyper-parameter : inverse scale parameter (rate parameter) for the Gamma distribution prior over the alpha parameter. Default Value 0.000001 |
opts.alpha_init? | number | Initial value for alpha (precision of the noise). If not set, alpha_init is 1/Var(y). |
opts.compute_score? | boolean | If true , compute the log marginal likelihood at each iteration of the optimization. Default Value false |
opts.copy_X? | boolean | If true , X will be copied; else, it may be overwritten. Default Value true |
opts.fit_intercept? | boolean | Whether to calculate the intercept for this model. The intercept is not treated as a probabilistic parameter and thus has no associated variance. If set to false , no intercept will be used in calculations (i.e. data is expected to be centered). Default Value true |
opts.lambda_1? | number | Hyper-parameter : shape parameter for the Gamma distribution prior over the lambda parameter. Default Value 0.000001 |
opts.lambda_2? | number | Hyper-parameter : inverse scale parameter (rate parameter) for the Gamma distribution prior over the lambda parameter. Default Value 0.000001 |
opts.lambda_init? | number | Initial value for lambda (precision of the weights). If not set, lambda_init is 1. |
opts.n_iter? | number | Maximum number of iterations. Should be greater than or equal to 1. Default Value 300 |
opts.tol? | number | Stop the algorithm if w has converged. Default Value 0.001 |
opts.verbose? | boolean | Verbose mode when fitting the model. Default Value false |
Returns
Defined in: generated/linear_model/BayesianRidge.ts:25 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/linear_model/BayesianRidge.ts:23 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/linear_model/BayesianRidge.ts:22 (opens in a new tab)
_py
PythonBridge
Defined in: generated/linear_model/BayesianRidge.ts:21 (opens in a new tab)
id
string
Defined in: generated/linear_model/BayesianRidge.ts:18 (opens in a new tab)
opts
any
Defined in: generated/linear_model/BayesianRidge.ts:19 (opens in a new tab)
Accessors
X_offset_
If fit\_intercept=True
, offset subtracted for centering data to a zero mean. Set to np.zeros(n_features) otherwise.
Signature
X_offset_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/linear_model/BayesianRidge.ts:495 (opens in a new tab)
X_scale_
Set to np.ones(n_features).
Signature
X_scale_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/linear_model/BayesianRidge.ts:520 (opens in a new tab)
alpha_
Estimated precision of the noise.
Signature
alpha_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/linear_model/BayesianRidge.ts:380 (opens in a new tab)
coef_
Coefficients of the regression model (mean of distribution)
Signature
coef_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/linear_model/BayesianRidge.ts:332 (opens in a new tab)
feature_names_in_
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Signature
feature_names_in_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/linear_model/BayesianRidge.ts:570 (opens in a new tab)
intercept_
Independent term in decision function. Set to 0.0 if fit\_intercept \= False
.
Signature
intercept_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/linear_model/BayesianRidge.ts:355 (opens in a new tab)
lambda_
Estimated precision of the weights.
Signature
lambda_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/linear_model/BayesianRidge.ts:403 (opens in a new tab)
n_features_in_
Number of features seen during fit.
Signature
n_features_in_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/linear_model/BayesianRidge.ts:545 (opens in a new tab)
n_iter_
The actual number of iterations to reach the stopping criterion.
Signature
n_iter_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/linear_model/BayesianRidge.ts:472 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/linear_model/BayesianRidge.ts:110 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/linear_model/BayesianRidge.ts:114 (opens in a new tab)
scores_
If computed_score is true
, value of the log marginal likelihood (to be maximized) at each iteration of the optimization. The array starts with the value of the log marginal likelihood obtained for the initial values of alpha and lambda and ends with the value obtained for the estimated alpha and lambda.
Signature
scores_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/linear_model/BayesianRidge.ts:449 (opens in a new tab)
sigma_
Estimated variance-covariance matrix of the weights
Signature
sigma_(): Promise<ArrayLike[]>;
Returns
Promise
<ArrayLike
[]>
Defined in: generated/linear_model/BayesianRidge.ts:426 (opens in a new tab)
Methods
dispose()
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Signature
dispose(): Promise<void>;
Returns
Promise
<void
>
Defined in: generated/linear_model/BayesianRidge.ts:175 (opens in a new tab)
fit()
Fit the model.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Training data. |
opts.sample_weight? | ArrayLike | Individual weights for each sample. |
opts.y? | ArrayLike | Target values. Will be cast to X’s dtype if necessary. |
Returns
Promise
<any
>
Defined in: generated/linear_model/BayesianRidge.ts:192 (opens in a new tab)
init()
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Signature
init(py: PythonBridge): Promise<void>;
Parameters
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/linear_model/BayesianRidge.ts:123 (opens in a new tab)
predict()
Predict using the linear model.
In addition to the mean of the predictive distribution, also its standard deviation can be returned.
Signature
predict(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Samples. |
opts.return_std? | boolean | Whether to return the standard deviation of posterior prediction. Default Value false |
Returns
Promise
<ArrayLike
>
Defined in: generated/linear_model/BayesianRidge.ts:241 (opens in a new tab)
score()
Return the coefficient of determination of the prediction.
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 of y
, disregarding the input features, would get a \(R^2\) score of 0.0.
Signature
score(opts: object): Promise<number>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | 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) , where n\_samples\_fitted is the number of samples used in the fitting for the estimator. |
opts.sample_weight? | ArrayLike | Sample weights. |
opts.y? | ArrayLike | True values for X . |
Returns
Promise
<number
>
Defined in: generated/linear_model/BayesianRidge.ts:285 (opens in a new tab)