mojolearn.ARDRegression#
- class mojolearn.ARDRegression(*, max_iter=300, tol=0.001, alpha_1=1e-06, alpha_2=1e-06, lambda_1=1e-06, lambda_2=1e-06, compute_score=False, threshold_lambda=10000.0, fit_intercept=True, copy_X=True, verbose=False)[source]#
Bases:
_LinearRegressorMixin,NumericModeMixinBayesian ARD (automatic relevance determination) regression.
Follows scikit-learn’s ARDRegression: one precision per weight, estimated by evidence maximization; features whose precision exceeds
threshold_lambdaare pruned (their weight is 0). Needs at least 2 samples.compute_score=Trueandpredict(return_std=True)raise ValueError;fittakes nosample_weight.- 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 each
lambda.compute_score (bool, default False) – Not supported: True raises ValueError.
threshold_lambda (float, default 1e4) – Precision above which a weight is pruned.
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:
coef_ (float32 array of shape (n_features,)) – Posterior mean of the weights.
intercept_ (float) – Intercept.
alpha_ (float) – Estimated noise precision.
lambda_ (float32 array of shape (n_features,)) – Estimated precision of each weight.
n_iter_ (int) – Number of iterations run.
n_features_in_ (int) – Number of features seen in
fit.
Examples
>>> import numpy as np, mojolearn >>> rng = np.random.default_rng(0) >>> X = rng.random((1000, 8), dtype=np.float32) >>> y = 3 * X[:, 0] - 2 * X[:, 1] >>> model = mojolearn.ARDRegression().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, compute_score=False, threshold_lambda=10000.0, fit_intercept=True, copy_X=True, verbose=False)[source]#
Methods
fit(X, y)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)[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.
- Returns:
self (ARDRegression) – The fitted model.
- Raises:
ValueError – If
compute_scoreis True or there are fewer than 2 samples.
- 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.