Modelling#
Ridge regression with built-in cross-validation for spectral modelling.
- class spectoprep.modelling.ridge.OptimizedRidgeCV(alphas=None, cv=5, scoring='neg_mean_squared_error', fit_intercept=True, gcv_mode=None, store_cv_results=False, groups=None)[source]#
Bases:
BaseEstimator,RegressorMixinRidge regression with alpha selected by cross-validation.
Thin, scikit-learn-compatible wrapper around
sklearn.linear_model.RidgeCVthat adds optional group-aware cross-validation.- Parameters:
alphas (array-like, default=None) – Alpha values to try. When
None,np.logspace(-3, 3, 10)is used. Resolved infit()so the estimator honours the scikit-learn contract that__init__only stores its arguments unchanged.cv (int, cross-validation generator, iterable or None, default=5) – Cross-validation splitting strategy. When
None,RidgeCVuses its efficient leave-one-out generalized cross-validation (GCV), andgcv_mode/store_cv_resultsbecome available.scoring (str or callable, default='neg_mean_squared_error') – Scoring used to select
alpha.fit_intercept (bool, default=True) – Whether to fit an intercept.
gcv_mode ({None, 'auto', 'svd', 'eigen'}, default=None) – GCV strategy. Only used when
cv is None.store_cv_results (bool, default=False) – Store per-alpha CV results in
cv_results_. Only valid whencv is None(RidgeCV restriction).groups (array-like, default=None) – Group labels. When provided (and
cvis notNone), grouped K-fold splits are materialised so no group is split across folds.
Notes
normalizewas removed from scikit-learn’sRidgeCVin 1.2 andstore_cv_valuesrenamed tostore_cv_resultsin 1.5; this wrapper tracks the current API. Standardise inputs with a scaler in aPipelineinstead of relying onnormalize.- set_fit_request(*, sample_weight='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (OptimizedRidgeCV)
- Returns:
self – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (OptimizedRidgeCV)
- Returns:
self – The updated object.
- Return type: