himalaya.ridge.RidgeCV¶
- class himalaya.ridge.RidgeCV(alphas=[0.1, 1], fit_intercept=False, solver='svd', solver_params=None, cv=5, Y_in_cpu=False, force_cpu=False)[source]¶
Ridge regression with efficient cross-validation over alpha.
Solve the ridge regression:
b* = argmin_b ||X @ b - Y||^2 + alpha ||b||^2,
with a grid-search over cross-validation to find the best alpha.
- Parameters
- alphasarray of shape (n_alphas, )
List of L2 regularization parameter to try.
- fit_interceptboolean
Whether to fit an intercept. If False, X and Y must be zero-mean over samples.
- solverstr
Algorithm used during the fit, “svd” only for now.
- solver_paramsdict or None
Additional parameters for the solver. See more details in the docstring of the function:
RidgeCV.ALL_SOLVERS[solver]
- cvint or scikit-learn splitter
Cross-validation splitter. If an int, KFold is used.
- Y_in_cpubool
If True, keep the target values
y
in CPU memory (slower).- force_cpubool
If True, computations will be performed on CPU, ignoring the current backend. If False, use the current backend.
Examples
>>> from himalaya.ridge import RidgeCV >>> import numpy as np >>> n_samples, n_features, n_targets = 10, 5, 3 >>> X = np.random.randn(n_samples, n_features) >>> Y = np.random.randn(n_samples, n_targets) >>> clf = RidgeCV() >>> clf.fit(X, Y) RidgeCV()
- Attributes
- coef_array of shape (n_features) or (n_features, n_targets)
Ridge coefficients.
- intercept_float or array of shape (n_targets, )
Intercept. Only returned when fit_intercept is True.
- best_alphas_array of shape (n_targets, )
Selected best hyperparameter alphas.
- cv_scores_array of shape (n_targets, )
Cross-validation scores averaged over splits, for the best alpha.
- n_features_in_int
Number of features used during the fit.
Methods
fit
(X[, y])Fit ridge regression model
get_params
([deep])Get parameters for this estimator.
predict
(X)Predict using the model.
score
(X, y)Return the coefficient of determination R^2 of the prediction.
set_params
(**params)Set the parameters of this estimator.