module documentation
This module implements a function to tune the sparsity parameter of a linear model using cross-validation.
Function | tune |
Tune the sparsity parameter (i.e. number of non-zero coefficients) of a linear model. |
Type Alias |
|
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.ndarray | The training data. The array should be of shape (n_samples, n_features) |
y:np.ndarray | The training labels. The array should be of shape (n_samples,). |
estimator:Estimator | The estimator to tune. This must be a SparseLinearRegressor instance (for regression problems) or
a SparseLinearClassifier instance (for classification problems). |
kint | The minimum value for the sparsity parameter (i.e. number of non-zero coefficients). |
kint | The maximum sparsity for the sparsity parameter (i.e. number of non-zero coefficients). If None , then
this is set to n_features . |
stepint | The 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 . |
maxOptional[ | 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:int | The number of cross-validation folds. |
returnbool | Whether to return the search log. |
showbool | Whether to show a progress bar. |
Returns | |
Union[ | The tuned estimator. If return_search_log is True , then a tuple of the tuned estimator and the search log. |