mojolearn.LassoCV#
- class mojolearn.LassoCV(*, eps=0.001, n_alphas='deprecated', alphas=100, fit_intercept=True, precompute='auto', max_iter=1000, tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=None, positive=False, random_state=None, selection='cyclic')[source]#
Bases:
_LinearRegressorMixin,NumericModeMixinLasso with
alphachosen by K-fold cross-validation along a path.Follows scikit-learn’s LassoCV, solved by coordinate descent: each fold fits the regularization path, the alpha with the lowest mean squared error across folds is chosen, and the model is refit on all rows.
cvmust be None or an int (unshuffled K-fold);selection='random'raises ValueError.- Parameters:
eps (float, default 1e-3) – Path length:
alpha_min / alpha_maxfor a generated grid.n_alphas (int or ‘deprecated’, default ‘deprecated’) – Grid size, used only when
alphasis None; prefer an intalphas.alphas (int or sequence of float, default 100) – Number of alphas on a generated grid, or the alphas to try.
fit_intercept (bool, default True) – Whether to fit an intercept.
precompute (bool, ‘auto’ or array, default ‘auto’) – Accepted for compatibility; ignored.
max_iter (int, default 1000) – Maximum number of coordinate-descent passes per alpha.
tol (float, default 1e-4) – Coordinate-descent stopping tolerance.
copy_X (bool, default True) – Accepted for compatibility;
Xis never modified.cv (int or None, default None) – Number of folds; None means 5.
verbose (bool, default False) – Accepted for compatibility; ignored.
n_jobs (int or None, default None) – Accepted for compatibility; ignored.
positive (bool, default False) – Restrict the weights to be non-negative.
random_state (int or None, default None) – Accepted for compatibility; ignored.
selection ({‘cyclic’}, default ‘cyclic’) – Only ‘cyclic’ is supported.
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:
alpha_ (float) – Selected alpha.
alphas_ (float32 array of shape (n_alphas,)) – Alphas tried, in decreasing order.
mse_path_ (float32 array of shape (n_alphas, n_folds)) – Mean squared error of each alpha on each fold.
coef_ (float32 array of shape (n_features,)) – Weights of the refit model.
intercept_ (float) – Intercept.
n_iter_ (int) – Coordinate-descent passes of the refit.
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.LassoCV(cv=5).fit(X, y) >>> model.alpha_
- __init__(*, eps=0.001, n_alphas='deprecated', alphas=100, fit_intercept=True, precompute='auto', max_iter=1000, tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=None, positive=False, random_state=None, selection='cyclic')[source]#
Methods
fit(X, y)Fit the model and select
alpha.get_params([deep])numeric_mode_used()The numeric mode this estimator runs in.
predict(X)Predict targets for
X.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 and select
alpha.- 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 (LassoCV) – The fitted model.
- Raises:
ValueError – If
selectionis not ‘cyclic’,cvis not None or an int in [2, n_samples], or no alpha is given.