📊 Metrics API Reference
Welcome to the KerasFactory Metrics documentation! All metrics are designed to work exclusively with Keras 3 and provide specialized statistical measurements for model analysis and anomaly detection tasks.
What You'll Find Here
Each metric includes detailed documentation with: - ✨ Complete parameter descriptions with types and defaults - 🎯 Usage examples showing real-world applications - ⚡ Best practices and performance considerations - 🎨 When to use guidance for each metric - 🔧 Implementation notes for developers
Ready-to-Use Metrics
These metrics provide specialized implementations for statistical analysis that you can use out-of-the-box or integrate into your models.
Keras 3 Compatible
All metrics are built on top of Keras base classes and are fully compatible with Keras 3.
📊 Statistical Metrics
📈 Median
Calculates the median of predicted values, providing a robust measure of central tendency less sensitive to outliers.
kerasfactory.metrics.Median
1 | |
A custom Keras metric that calculates the median of the predicted values.
This class is a custom implementation of a Keras metric, which calculates the median of the predicted values during model training. The median is a robust measure of central tendency that is less sensitive to outliers compared to the mean, making it particularly useful for anomaly detection tasks.
Attributes:
| Name | Type | Description |
|---|---|---|
values |
Variable
|
A trainable weight that stores the calculated median. |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Initializes the Median metric with a given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name of the metric. Defaults to 'median'. |
'median'
|
**kwargs |
Any
|
Additional keyword arguments passed to the parent class. |
{}
|
Source code in kerasfactory/metrics/median.py
58 59 60 61 62 63 64 65 66 67 68 | |
Functions
update_state
1 | |
Updates the state of the metric with the median of the predicted values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_pred |
KerasTensor
|
The predicted values. |
required |
Source code in kerasfactory/metrics/median.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
result
1 | |
Returns the current state of the metric, i.e., the current median.
Returns:
| Name | Type | Description |
|---|---|---|
KerasTensor |
KerasTensor
|
The current median. |
Source code in kerasfactory/metrics/median.py
93 94 95 96 97 98 99 | |
from_config
classmethod
1 | |
Creates a new instance of the metric from its config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config |
dict
|
A dictionary containing the configuration of the metric. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Median |
Median
|
A new instance of the metric. |
Source code in kerasfactory/metrics/median.py
110 111 112 113 114 115 116 117 118 119 120 | |
📉 StandardDeviation
Calculates the standard deviation of predicted values, useful for tracking prediction variability and uncertainty.
kerasfactory.metrics.StandardDeviation
1 2 3 | |
A custom Keras metric that calculates the standard deviation of the predicted values.
This class is a custom implementation of a Keras metric, which calculates the standard deviation of the predicted values during model training. It's particularly useful for anomaly detection tasks where you need to track the variability of model predictions.
Attributes:
| Name | Type | Description |
|---|---|---|
values |
Variable
|
A trainable weight that stores the calculated standard deviation. |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Initializes the StandardDeviation metric with a given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name of the metric. Defaults to 'standard_deviation'. |
'standard_deviation'
|
**kwargs |
Any
|
Additional keyword arguments passed to the parent class. |
{}
|
Source code in kerasfactory/metrics/standard_deviation.py
57 58 59 60 61 62 63 64 65 66 67 | |
Functions
update_state
1 | |
Updates the state of the metric with the standard deviation of the predicted values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_pred |
KerasTensor
|
The predicted values. |
required |
Source code in kerasfactory/metrics/standard_deviation.py
69 70 71 72 73 74 75 | |
result
1 | |
Returns the current state of the metric, i.e., the current standard deviation.
Returns:
| Name | Type | Description |
|---|---|---|
KerasTensor |
KerasTensor
|
The current standard deviation. |
Source code in kerasfactory/metrics/standard_deviation.py
77 78 79 80 81 82 83 | |
from_config
classmethod
1 | |
Creates a new instance of the metric from its config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config |
dict
|
A dictionary containing the configuration of the metric. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StandardDeviation |
StandardDeviation
|
A new instance of the metric. |
Source code in kerasfactory/metrics/standard_deviation.py
94 95 96 97 98 99 100 101 102 103 104 | |