mojolearn.BayesianRidge#
- class mojolearn.BayesianRidge(*, max_iter=300, tol=0.001, alpha_1=1e-06, alpha_2=1e-06, lambda_1=1e-06, lambda_2=1e-06, alpha_init=None, lambda_init=None, compute_score=False, fit_intercept=True, copy_X=True, verbose=False)[source]#
Bases:
_LinearRegressorMixin,NumericModeMixinBayesian ridge regression.
Follows scikit-learn’s BayesianRidge: estimates the noise precision
alpha_and the weight precisionlambda_by maximizing the marginal likelihood (evidence).compute_score=Trueandpredict(return_std=True)raise ValueError.- Parameters:
max_iter (int, default 300) – Maximum number of iterations.
tol (float, default 1e-3) – Stop when the weights change by less than this.
alpha_1, alpha_2 (float, default 1e-6) – Shape and rate of the Gamma prior over
alpha.lambda_1, lambda_2 (float, default 1e-6) – Shape and rate of the Gamma prior over
lambda.alpha_init (float or None, default None) – Starting value of
alpha; None starts from the inverse variance ofy.lambda_init (float or None, default None) – Starting value of
lambda; None starts from 1.compute_score (bool, default False) – Not supported: True raises ValueError.
fit_intercept (bool, default True) – Whether to fit an intercept.
copy_X (bool, default True) – Accepted for compatibility;
Xis never modified.verbose (bool, default False) – Accepted for compatibility; ignored.
numeric_mode (str or None, default None) – Numeric mode for this model (
'identical','deterministic'or'fast', which runs on Apple GPUs only); None uses the process default (seemojolearn.set_numeric_mode()).
- Variables:
Examples
>>> import numpy as np, mojolearn >>> rng = np.random.default_rng(0) >>> X = rng.random((1000, 8), dtype=np.float32) >>> y = X @ np.arange(8, dtype=np.float32) >>> model = mojolearn.BayesianRidge().fit(X, y)
- __init__(*, max_iter=300, tol=0.001, alpha_1=1e-06, alpha_2=1e-06, lambda_1=1e-06, lambda_2=1e-06, alpha_init=None, lambda_init=None, compute_score=False, fit_intercept=True, copy_X=True, verbose=False)[source]#
Methods
fit(X, y[, sample_weight])Fit the model.
get_params([deep])numeric_mode_used()The numeric mode this estimator runs in.
predict(X[, return_std])Predict targets with the posterior mean of the weights.
score(X, y)Coefficient of determination R^2 of
predict(X)againsty.set_params(**params)Set constructor parameters.
vendor_used()The GPU backend this estimator runs on.
- fit(X, y, sample_weight=None)[source]#
Fit the model.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training data, converted to float32; values must be finite.
y (array-like of shape (n_samples,)) – Targets.
sample_weight (array-like of shape (n_samples,) or float, optional) – Non-negative weights with a positive sum.
- Returns:
self (BayesianRidge) – The fitted model.
- Raises:
ValueError – If
compute_scoreis True or the weights are invalid.
- predict(X, return_std=False)[source]#
Predict targets with the posterior mean of the weights.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples, converted to float32.
return_std (bool, default False) – Not supported: True raises ValueError.
- Returns:
y_pred (float32 array of shape (n_samples,)) – Predicted values.