You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The coefficients coef_ are not calculated based on the alpha_ and lambda_ value returned in in the Bayesian Ridge regression model as these two properties are modified after the coef_ calculation. This can be seen in this reduced excerpt from the code in sklearn/linear_model/bayes.py.
# Convergence loop of the bayesian ridge regression
for iter_ in range(self.n_iter):
# Compute mu and sigma
# sigma_ = lambda_ / alpha_ * np.eye(n_features) + np.dot(X.T, X)
# coef_ = sigma_^-1 * XT * y
** lambda_ and alpha_ are used to calculate coef_**
coef_ = ...
...
# Update alpha and lambda
...
**lambda_ and alpha_ are modified**
lambda_ = ((gamma_ + 2 * lambda_1) /
(np.sum(coef_ ** 2) + 2 * lambda_2))
alpha_ = ((n_samples - gamma_ + 2 * alpha_1) /
(rmse_ + 2 * alpha_2))
# Compute the objective function
...
# Check for convergence
...
self.alpha_ = alpha_
self.lambda_ = lambda_
self.coef_ = coef_
A possible solution would be keeping a copy of alpha_ and lambda_ at the point of calculation of coef_ and assign these copies to self.alpha_ and self.lambda_. Alternatively, move the assignment to self.alpha_ and self.lambda_ to the point of calculation of coef_.
The text was updated successfully, but these errors were encountered:
The coefficients
coef_
are not calculated based on thealpha_
andlambda_
value returned in in the Bayesian Ridge regression model as these two properties are modified after thecoef_
calculation. This can be seen in this reduced excerpt from the code insklearn/linear_model/bayes.py
.A possible solution would be keeping a copy of
alpha_
andlambda_
at the point of calculation ofcoef_
and assign these copies toself.alpha_
andself.lambda_
. Alternatively, move the assignment toself.alpha_
andself.lambda_
to the point of calculation ofcoef_
.The text was updated successfully, but these errors were encountered: