sklearn_utils module¶
Contains Lasso scikit-learn
utility programs:
skl_npreg_lasso
: Lasso regression on polynomial interactions of the covariatesplot_lasso_path
: plots the Lasso coefficient paths.
plot_lasso_path(y, X, eps=0.001, *, standardize=True, ax=None)
¶
Compute and plot the Lasso regularization path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y
|
ndarray
|
Response vector of shape |
required |
X
|
ndarray
|
Feature matrix of shape |
required |
eps
|
float
|
Path length parameter passed to |
0.001
|
standardize
|
bool
|
When |
True
|
ax
|
Axes | None
|
Optional Matplotlib |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
A tuple |
ndarray
|
strengths, |
Axes
|
Matplotlib axes used for plotting. |
Source code in bs_python_utils/sklearn_utils.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
skl_npreg_lasso(y, X, alpha, degree=4, *, include_bias=False, return_model=False, lasso_kwargs=None)
¶
Fit a polynomial Lasso regression with standard preprocessing.
Inputs are reshaped if necessary and passed through a StandardScaler
followed by
PolynomialFeatures
and Lasso
. Extra keyword arguments can be forwarded to the Lasso
estimator, and the fitted pipeline can optionally be returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y
|
ndarray
|
Response vector of shape |
required |
X
|
ndarray
|
Feature matrix of shape |
required |
alpha
|
float
|
Lasso penalty parameter. |
required |
degree
|
int
|
Total polynomial degree for |
4
|
include_bias
|
bool
|
When |
False
|
return_model
|
bool
|
If |
False
|
lasso_kwargs
|
dict[str, Any] | None
|
Extra keyword arguments forwarded to |
None
|
Returns:
Type | Description |
---|---|
ndarray | tuple[ndarray, Pipeline]
|
Either the fitted values |
ndarray | tuple[ndarray, Pipeline]
|
|
Source code in bs_python_utils/sklearn_utils.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|