Skip to content

Instantly share code, notes, and snippets.

@Eligijus112
Created September 23, 2022 05:10
Show Gist options
  • Save Eligijus112/1088a916a2cdaa4beae8693e1c8c5da1 to your computer and use it in GitHub Desktop.
Save Eligijus112/1088a916a2cdaa4beae8693e1c8c5da1 to your computer and use it in GitHub Desktop.
From sklearn to tensorflow regularization
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