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, keras.losses.Loss instance or a callable.

Parameters:

loss (str | 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 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 keras.metrics.Metric instance a class inheriting from keras.metrics.Metric.

Parameters:

metric (str | 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 keras.metrics as metrics
>>> metric_name(metrics.BinaryCrossentropy)
'BinaryCrossentropy'
>>> metric_name(metrics.binary_crossentropy)
'binary_crossentropy'