module documentation

This module implements a function to tune the sparsity parameter of a linear model using cross-validation.

Function tune_estimator Tune the sparsity parameter (i.e. number of non-zero coefficients) of a linear model.
Type Alias Estimator Undocumented
def tune_estimator(X: np.ndarray, y: np.ndarray, estimator: Estimator, k_min: int = 1, k_max: int = None, step_size: int = 1, max_iters_no_improvement: Optional[int] = None, cv: int = 3, return_search_log: bool = False, show_progress_bar: bool = False) -> Union[Estimator, tuple[Estimator, pd.DataFrame]]: (source)

Tune the sparsity parameter (i.e. number of non-zero coefficients) of a linear model.

The sparsity parameter is tuned by performing a grid search over the range [k_min, k_max] with step size step_size. If the test score does not improve for max_iters_no_improvement iterations, then the search is terminated early.

Parameters
X:np.ndarrayThe training data. The array should be of shape (n_samples, n_features)
y:np.ndarrayThe training labels. The array should be of shape (n_samples,).
estimator:EstimatorThe estimator to tune. This must be a SparseLinearRegressor instance (for regression problems) or a SparseLinearClassifier instance (for classification problems).
k_min:intThe minimum value for the sparsity parameter (i.e. number of non-zero coefficients).
k_max:intThe maximum sparsity for the sparsity parameter (i.e. number of non-zero coefficients). If None, then this is set to n_features.
step_size:intThe step size for the search. The sparsity parameter is incremented by this value at each iteration. Must be less than or equal to k_max - k_min.
max_iters_no_improvement:Optional[int]The maximum number of iterations without improvement in the CV test score before the search is terminated. If None, then no early stopping is performed.
cv:intThe number of cross-validation folds.
return_search_log:boolWhether to return the search log.
show_progress_bar:boolWhether to show a progress bar.
Returns
Union[Estimator, tuple[Estimator, pd.DataFrame]]The tuned estimator. If return_search_log is True, then a tuple of the tuned estimator and the search log.