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, BaseEstimator

Lasso with gradient-based α tuning, sklearn-compatible.

The outer search is sparho.hoag_search() by default. The inner solver defaults to sparho.adapters.SklearnLasso. The default validation criterion is 5-fold CrossVal over the training data.

Parameters:
  • alpha_init – Starting α for the outer search (must be > 0; the search optimizes in log α space).

  • fit_intercept – Center X and y before the inner solve, then reconstruct the intercept from the means and coef_. Dense X only — sparse X with fit_intercept=True raises; use fit_intercept=False plus StandardScaler(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 if criterion is supplied.

  • random_state – Seed for the default CrossVal fold split. Ignored if criterion is supplied.

  • verbose0 (default) is silent. 1 prints one line per outer iter via a default _VerbosePrinter callback wired into the search. 2 adds step_size / L_estimate to each line (HOAG only).

coef_
Type:

ndarray of shape (n_features,)

intercept_
Type:

float

alpha_
Type:

float

n_iter_
Type:

int

feature_names_in_
Type:

ndarray, present only when X is a DataFrame

n_features_in_
Type:

int

search_result_
Type:

sparho.SearchResult

__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]
Parameters:
Return type:

None

fit(X, y, sample_weight=None)[source]
Parameters:
Return type:

LassoHO

predict(X)[source]
Parameters:

X (ndarray[tuple[Any, ...], dtype[floating]])

Return type:

ndarray[tuple[Any, …], dtype[floating]]

set_fit_request(*, sample_weight='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the fit method.

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 (see sklearn.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 to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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_weight parameter in fit.

  • self (LassoHO)

Returns:

self – The updated object.

Return type:

object

set_score_request(*, sample_weight='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

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 (see sklearn.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 to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • 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_weight parameter in score.

  • self (LassoHO)

Returns:

self – The updated object.

Return type:

object

class sparho.ElasticNetHO[source]

Bases: RegressorMixin, BaseEstimator

ElasticNet with gradient-based α tuning, sklearn-compatible.

Same shape as LassoHO plus the structural mixing weight rho (sklearn’s l1_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]. ρ = 1 recovers 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]
Parameters:
Return type:

None

fit(X, y, sample_weight=None)[source]
Parameters:
Return type:

ElasticNetHO

predict(X)[source]
Parameters:

X (ndarray[tuple[Any, ...], dtype[floating]])

Return type:

ndarray[tuple[Any, …], dtype[floating]]

set_fit_request(*, sample_weight='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the fit method.

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 (see sklearn.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 to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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_weight parameter in fit.

  • self (ElasticNetHO)

Returns:

self – The updated object.

Return type:

object

set_score_request(*, sample_weight='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

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 (see sklearn.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 to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • 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_weight parameter in score.

  • self (ElasticNetHO)

Returns:

self – The updated object.

Return type:

object

class sparho.LogisticRegressionHO[source]

Bases: ClassifierMixin, BaseEstimator

Sparse-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’s LogisticLoss requires; predictions come back in the original label space via classes_.

fit_intercept=True is 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 to X manually, or use fit_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 False in v0.3. Kept on the signature so future versions can add intercept support without breaking set_params callers.

__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]
Parameters:
Return type:

None

fit(X, y, sample_weight=None)[source]
Parameters:
Return type:

LogisticRegressionHO

decision_function(X)[source]
Parameters:

X (ndarray[tuple[Any, ...], dtype[floating]])

Return type:

ndarray[tuple[Any, …], dtype[floating]]

predict(X)[source]
Parameters:

X (ndarray[tuple[Any, ...], dtype[floating]])

Return type:

ndarray[tuple[Any, …], dtype[floating]]

predict_proba(X)[source]
Parameters:

X (ndarray[tuple[Any, ...], dtype[floating]])

Return type:

ndarray[tuple[Any, …], dtype[floating]]

set_fit_request(*, sample_weight='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the fit method.

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 (see sklearn.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 to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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_weight parameter in fit.

  • self (LogisticRegressionHO)

Returns:

self – The updated object.

Return type:

object

set_score_request(*, sample_weight='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

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 (see sklearn.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 to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • 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_weight parameter in score.

  • self (LogisticRegressionHO)

Returns:

self – The updated object.

Return type:

object