Closed
Description
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_
.