scikeras.utils

Functions

loss_name(loss)

Retrieves a loss's full name (eg: "mean_squared_error").

metric_name(metric)

Retrieves a metric's full name (eg: "mean_squared_error").

scikeras.utils.loss_name(loss)[source]

Retrieves a loss’s full name (eg: “mean_squared_error”).

Parameters
lossUnion[str, Loss, Callable]

Instance of Keras Loss, loss callable or string shorthand (eg: “mse”) or full name (“mean_squared_error”).

Returns
str

String name of the loss.

Raises
TypeError

If loss is not a string, tf.keras.losses.Loss instance or a callable.

Parameters

loss (Union[str, keras.losses.Loss, Callable]) –

Return type

str

Notes

The result of this function will always be in snake case, not camel case.

Examples

>>> loss_name("BinaryCrossentropy")
'binary_crossentropy'
>>> loss_name("binary_crossentropy")
'binary_crossentropy'
>>> import tensorflow.keras.losses as losses
>>> loss_name(losses.BinaryCrossentropy)
'binary_crossentropy'
>>> loss_name(losses.binary_crossentropy)
'binary_crossentropy'
scikeras.utils.metric_name(metric)[source]

Retrieves a metric’s full name (eg: “mean_squared_error”).

Parameters
metricsUnion[str, Metric, Callable]

Instance of Keras Metric, metric callable or string shorthand (eg: “mse”) or full name (“mean_squared_error”).

Returns
str

Full name for Keras metric. Ex: “mean_squared_error”.

Raises
TypeError

If metric is not a string, a tf.keras.metrics.Metric instance a class inheriting from tf.keras.metrics.Metric.

Parameters

metric (Union[str, keras.metrics.Metric, Callable]) –

Return type

str

Notes

The result of this function will always be in snake case, not camel case.

Examples

>>> metric_name("BinaryCrossentropy")
'BinaryCrossentropy'
>>> metric_name("binary_crossentropy")
'binary_crossentropy'
>>> import tensorflow.keras.metrics as metrics
>>> metric_name(metrics.BinaryCrossentropy)
'BinaryCrossentropy'
>>> metric_name(metrics.binary_crossentropy)
'binary_crossentropy'