sklearn-compatible wrappers¶
The wrappers expose sparho’s bilevel α-tuning behind the
BaseEstimator + Mixin API the sklearn ecosystem expects. They unlock
Pipeline composition, GridSearchCV over structural parameters (e.g.
ElasticNet’s rho), cross_val_score, clone,
permutation_importance, MLflow autolog, and EconML / DoubleML
integration.
- class sparho.LassoHO[source]¶
Bases:
RegressorMixin,BaseEstimatorLasso with gradient-based α tuning, sklearn-compatible.
The outer search is
sparho.hoag_search()by default. The inner solver defaults tosparho.adapters.SklearnLasso. The default validation criterion is 5-foldCrossValover the training data.- Parameters:
alpha_init – Starting α for the outer search (must be
> 0; the search optimizes inlog αspace).fit_intercept – Center
Xandybefore the inner solve, then reconstruct the intercept from the means andcoef_. Dense X only — sparse X withfit_intercept=Trueraises; usefit_intercept=FalseplusStandardScaler(with_mean=False).n_iter – Maximum outer iterations.
solver – Inner solver; defaults to
SklearnLasso(tol=inner_tol).criterion – Validation oracle; defaults to a 5-fold
CrossVal(HeldOutMSE, warm_start=True).outer –
"hoag"(default) or"grad".inner_tol – Inner-solver tolerance. Threaded through to the default solver and the HOAG schedule.
cv_folds – Number of folds for the default
CrossVal. Ignored ifcriterionis supplied.random_state – Seed for the default
CrossValfold split. Ignored ifcriterionis supplied.verbose –
0(default) is silent.1prints one line per outer iter via a default_VerbosePrintercallback wired into the search.2addsstep_size/L_estimateto each line (HOAG only).
- coef_¶
- Type:
ndarray of shape (n_features,)
- feature_names_in_¶
- Type:
ndarray, present only when
Xis a DataFrame
- search_result_¶
- Type:
- __init__(alpha_init=1.0, *, fit_intercept=True, n_iter=30, solver=None, criterion=None, outer='hoag', inner_tol=1e-06, cv_folds=5, random_state=None, verbose=0)[source]¶
- 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.
- 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.
- class sparho.ElasticNetHO[source]¶
Bases:
RegressorMixin,BaseEstimatorElasticNet with gradient-based α tuning, sklearn-compatible.
Same shape as
LassoHOplus the structural mixing weightrho(sklearn’sl1_ratio). The penalty isα · (ρ·‖β‖₁ + (1−ρ)/2·‖β‖²); onlyαis tuned by the outer search.- Parameters:
alpha_init – See
LassoHO.fit_intercept – See
LassoHO.n_iter – See
LassoHO.solver – See
LassoHO.criterion – See
LassoHO.outer – See
LassoHO.inner_tol – See
LassoHO.cv_folds – See
LassoHO.random_state – See
LassoHO.rho – Mixing weight
ρ ∈ (0, 1].ρ = 1recovers Lasso. Structural — not tuned by the search.
- __init__(alpha_init=1.0, *, rho=0.5, fit_intercept=True, n_iter=30, solver=None, criterion=None, outer='hoag', inner_tol=1e-06, cv_folds=5, random_state=None, verbose=0)[source]¶
- 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 (ElasticNetHO)
- 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 (ElasticNetHO)
- Returns:
self – The updated object.
- Return type:
- class sparho.LogisticRegressionHO[source]¶
Bases:
ClassifierMixin,BaseEstimatorSparse-L1 logistic regression with gradient-based α tuning.
Wraps
sparho.adapters.SklearnLogisticRegression(liblinear, L1). The fit accepts arbitrary 2-class labels and internally remaps to the{−1, +1}convention sparho’sLogisticLossrequires; predictions come back in the original label space viaclasses_.fit_intercept=Trueis not supported in v0.3 — the log-odds intercept is a separate degree of freedom, not recoverable from feature centering. Either append a constant column toXmanually, or usefit_intercept=False(the default for this estimator).- Parameters:
alpha_init – See
LassoHO.n_iter – See
LassoHO.solver – See
LassoHO.criterion – See
LassoHO.outer – See
LassoHO.inner_tol – See
LassoHO.cv_folds – See
LassoHO.random_state – See
LassoHO.fit_intercept – Must be
Falsein v0.3. Kept on the signature so future versions can add intercept support without breakingset_paramscallers.
- __init__(alpha_init=1.0, *, fit_intercept=False, n_iter=30, solver=None, criterion=None, outer='hoag', inner_tol=1e-06, cv_folds=5, random_state=None, verbose=0)[source]¶
- 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 (LogisticRegressionHO)
- 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 (LogisticRegressionHO)
- Returns:
self – The updated object.
- Return type: