Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn BayesianRidge

From Leeroopedia


Knowledge Sources
Domains Machine Learning, Bayesian Regression
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete tool for Bayesian ridge regression with automatic regularization parameter tuning provided by scikit-learn.

Description

BayesianRidge implements Bayesian ridge regression, fitting a Bayesian ridge model by optimizing the regularization parameters lambda (precision of the weights) and alpha (precision of the noise). The model places Gamma priors over the alpha and lambda parameters and iteratively updates them using evidence maximization (type-II maximum likelihood). This approach automatically determines the optimal regularization strength from the data itself, unlike standard ridge regression where the regularization parameter must be set manually.

Usage

Use BayesianRidge when you need a regression model that automatically tunes its regularization strength, when you want uncertainty estimates on predictions, or when you want to compute the log marginal likelihood for model comparison. It is particularly useful when you have limited data and want to avoid overfitting without manual hyperparameter tuning.

Code Reference

Source Location

Signature

class BayesianRidge(RegressorMixin, LinearModel):
    def __init__(
        self,
        *,
        max_iter=300,
        tol=1e-3,
        alpha_1=1e-6,
        alpha_2=1e-6,
        lambda_1=1e-6,
        lambda_2=1e-6,
        alpha_init=None,
        lambda_init=None,
        compute_score=False,
        fit_intercept=True,
        copy_X=True,
        verbose=False,
    ):

Import

from sklearn.linear_model import BayesianRidge

I/O Contract

Inputs

Name Type Required Description
max_iter int No Maximum number of iterations over the complete dataset (default=300)
tol float No Convergence threshold for stopping the algorithm (default=1e-3)
alpha_1 float No Shape parameter for the Gamma distribution prior over alpha (default=1e-6)
alpha_2 float No Inverse scale parameter for the Gamma distribution prior over alpha (default=1e-6)
lambda_1 float No Shape parameter for the Gamma distribution prior over lambda (default=1e-6)
lambda_2 float No Inverse scale parameter for the Gamma distribution prior over lambda (default=1e-6)
alpha_init float No Initial value for alpha (precision of noise); defaults to 1/Var(y)
lambda_init float No Initial value for lambda (precision of weights); defaults to 1
compute_score bool No Whether to compute log marginal likelihood at each iteration (default=False)
fit_intercept bool No Whether to calculate the intercept (default=True)
copy_X bool No Whether to copy X (default=True)

Outputs

Name Type Description
coef_ ndarray of shape (n_features,) Coefficients of the regression model
intercept_ float Estimated independent term in the linear model
alpha_ float Estimated precision of the noise
lambda_ float Estimated precision of the weights
sigma_ ndarray of shape (n_features, n_features) Estimated variance-covariance matrix of the weights
scores_ array-like of shape (n_iter_+1,) Log marginal likelihood at each iteration (if compute_score=True)

Usage Examples

Basic Usage

from sklearn.linear_model import BayesianRidge
from sklearn.datasets import make_regression

X, y = make_regression(n_samples=100, n_features=10, noise=10, random_state=42)
model = BayesianRidge()
model.fit(X, y)
predictions = model.predict(X)
print("Alpha:", model.alpha_)
print("Lambda:", model.lambda_)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment