Sparse-lm estimator handling#

Utility functions to prepare sparse-lm estimators.

estimator_factory(estimator_name, **kwargs)[source]#

Get an estimator object from its class name.

Parameters:
  • estimator_name (str) – The name of the estimator.

  • **kwargs – Other keyword arguments to initialize an estimator. Depends on the specific class

Returns:

Packed estimator or stepwise estimator to be used directly for fitting.

Return type:

Estimator

is_subclass(classname, parent_classname)[source]#

Check whether the estimator is a subclass of some parent.

Parameters:
  • classname (str) – Name of the sparse-lm estimator class.

  • parent_classname (str) – Name of the parent class. Also in sparselm.model.

Returns:

Whether the given class is a subclass of another given class.

Return type:

bool

optimizer_factory(optimizer_name, estimator, param_grid=None, **kwargs)[source]#

Get an optimizer object from its class name.

Parameters:
  • optimizer_name (str) – Name of the optimizer.

  • estimator (CVXRegressor) – An estimator used to initialize the optimizer.

  • param_grid (dict or list of tuple) – Parameters grid used to initialize the optimizer. Format depends on the type of optimizer. See sparselm.model_selection.

  • **kwargs – Other keyword arguments to initialize an optimizer. Depends on the specific class used.

Returns:

An initialized model selection object.

Return type:

GridSearchCV or LineSearchCV

prepare_estimator(cluster_subspace, estimator_name, optimizer_name, param_grid=None, use_hierarchy=True, center_point_external=True, estimator_kwargs=None, optimizer_kwargs=None)[source]#

Prepare an estimator for fitting.

Note

Sample weights are not supported yet.

Parameters:
  • cluster_subspace (ClusterSubspace) – A ClusterSubspace to expand with.

  • estimator_name (str) – The name of estimator, following the rules in smol.utils.

  • optimizer_name (str) – The name of the model optimizer. Currently, only supports GridSearch and LineSearch.

  • param_grid (dict|list[tuple]) – Parameter grid to initialize the optimizer. See docs of the sparselm.model_selection module. Not needed when using OrdinaryLeastSquares.

  • use_hierarchy (bool) – optional Whether to use the cluster hierarchy constraints when available. Default to true.

  • center_point_external (bool) – optional Whether to fit the point and external terms with linear regression first, then fit the residue with regressor. Default to true, because this usually greatly improves the decrease of ECI over cluster radius.

  • estimator_kwargs (dict) – optional Other keyword arguments to initialize an estimator.

  • optimizer_kwargs (dict) – optional Other keyword arguments to initialize an optimizer.

Returns:

The estimator wrapped up for fitting.

Return type:

Estimator