Created
September 23, 2022 05:10
-
-
Save Eligijus112/1088a916a2cdaa4beae8693e1c8c5da1 to your computer and use it in GitHub Desktop.
From sklearn to tensorflow regularization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def elastic_net_to_keras(alpha: float, l1_ratio: float): | |
""" | |
Converts ElasticNet parameters from sklearn to Keras regularizers. | |
Arguments | |
--------- | |
alpha: float | |
The regularization strength of the model. | |
l1_ratio: float | |
The l1 regularization ratio of the model. | |
Returns | |
------- | |
l1: float | |
The l1 regularization strength of the model in tensorflow | |
l2: float | |
The l2 regularization strength of the model in tensorflow | |
""" | |
l1 = alpha * l1_ratio | |
l2 = alpha * (1 - l1_ratio) / 2 | |
return l1, l2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment