-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Add Penalty factors for each coefficient in enet (similar to the R's glmnet library) #11566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
…y for each variable (scikit-learn#11566)
sounds like a reasonable addition. please open the PR. I can't guarantee that it'll get accepted but it makes sense to me. |
…y for each variable (scikit-learn#11566)
…y for each variable (scikit-learn#11566)
…y for each variable (scikit-learn#11566)
This feature is also implemented in #9405, where you can exclude coefficients from the L1 as well as from the L2 penalty term. |
If possible could penalty factors also be added to |
How do we want the API?
Among the estimators are:
What do we do with the CV variants? I would leave them untouched for the moment. @scikit-learn/core-devs as info |
one issue I foresee is the ambiguity between an array of alpha with one
alpha for each output task
and one alpha per feature.... hum... otherwise the alpha as array of length
n_features is the simplest
… Message ID: ***@***.***>
|
can I get a review on my pull request that addresses this issue? |
Ridge already accepts |
Can we accept shape (n_targets,), (1, n_targets), (n_features, 1) or (n_features, n_targets)? |
Personally, I find the multi-output story for penalties a bit unfortunate (maybe I'm blind or unaware of good use cases). Given that we can't change that (easily), what about introducing new parameters In particular the Further advantages:
|
What is |
It's the number of targets in from sklearn.datasets import make_regression
from sklearn.linear_model import Ridge
X, y = make_regression(n_targets=2, random_state=0)
print(y.shape)
# (100, 2)
reg = Ridge().fit(X, y)
print(reg.coef_.shape)
# (2, 100) |
ah ok thanks, haven't ever had the need to fit a regression w/ multiple targets before |
Personally, I find the multi-output story for penalties a bit unfortunate
(maybe I'm blind or unaware of good use cases).
I think the motivating use case is when the targets are mapping to time
samples. You want to fit one model per temporal
observations and you want to factorize some computations as X does not
depend on the target
Given that we can't change that (easily), what about introducing new
parameters P1 and P2 as in https://glum.readthedocs.io/en/latest/glm.html
(and as in #9405 <#9405>)
for *penalty matrix for l1* and *penalty matrix for l2*.
that would work yes. But to me P1 cannot be a generic matrix as otherwise
the solvers will be a lot more complicated.
In GLUM I think it can only be a diagonal matrix.
In particular the P2 would be nice to have as it generalizes the penalty
to coef @ P2 @ coef. This can come in very handy, e.g. for penalizing
differences of coefficients or just for different penalty strength per
feature.
+1
… Further advantages:
- unified way to specify feature-wise penalties across all (linear)
estimators: always the same parameter name
- clear distinction between l1 and l2
- no mixing/confusion with n_targets
works for me!
Message ID: ***@***.***>
|
Correct, a 1d array for the diagonals of a |
As discussed in the dev meeting 28 March 2022, new parameter(s) seems fine. The questions are:
One vs twoHaving one parameter like |
Having two individual ones, like P1 and P2 for ||P1 * w||_1 and ||w' @
diag(P2) @ w||, would allow more control. It also opens the opportunity
for later to allow P2 to be a 2d array.
this seems more flexible. Would you have an example in mind to illustrate
the benefit of this
on some data? I think that without a good example this feature will remain
largely hidden.
|
There are several use cases:
|
Thanks for the effort on this so far. Could the new parameter(s) for flexible penalization of coefficients also be added to other models using the elastic net regularizer? Here's another paper that could add some motivation for selective penalization from single-cell RNAseq bioinformatics: https://doi.org/10.1093/bioinformatics/btac227. In an attempt to make this method available in python, I saw the use case for coefficient-specific penalization in |
I did this PR as part of a school project so I'm unable to devote anytime to this anymore. |
Description
This is a feature request in allow flexibility in elastic net, which allows the user to apply separate penalties to each coefficient of the L1 term. The default value of this penalty factor is 1, meaning the regular elastic net behavior. If the penalty factor of a feature is Zero, it means it's not penalized at all, and that the user wants this feature to be always there in the model.
This feature is very useful in Bioinformatics and systems biology (that's why it is in Stanford's R package glmnet). With this feature, the user can run feature selection on a set of genes while making sure some genes stay in the system and not penalized (because of prior knowledge that they are involvid the system).
Here is glmnet documentation explaining the penalty factor. Mainly, it's controlling the selection weight on the lasso term:
https://web.stanford.edu/~hastie/glmnet/glmnet_alpha.html#lin
This feature is used in several papers, I've implemented in it in one of mine in scikit-learn. I've requests from other biologists to use this method in Python without having to recompile scikit-learn. I can do a pull request with this feature.
Papers using this feature:
The text was updated successfully, but these errors were encountered: