TFMA Metrics¶
tensorflow_model_analysis.metrics
¶
Init module for TensorFlow Model Analysis metrics.
Attributes¶
MetricComputations
module-attribute
¶
MetricComputations = List[
Union[
MetricComputation,
DerivedMetricComputation,
CrossSliceMetricComputation,
CIDerivedMetricComputation,
]
]
Classes¶
AUC
¶
AUC(
num_thresholds: Optional[int] = None,
curve: str = "ROC",
summation_method: str = "interpolation",
name: Optional[str] = None,
thresholds: Optional[Union[float, List[float]]] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetricBase
Approximates the AUC (Area under the curve) of the ROC or PR curves.
The AUC (Area under the curve) of the ROC (Receiver operating characteristic; default) or PR (Precision Recall) curves are quality measures of binary classifiers. Unlike the accuracy, and like cross-entropy losses, ROC-AUC and PR-AUC evaluate all the operational points of a model.
This class approximates AUCs using a Riemann sum. During the metric accumulation phase, predictions are accumulated within predefined buckets by value. The AUC is then computed by interpolating per-bucket averages. These buckets define the evaluated operational points.
This metric uses true_positives
, true_negatives
, false_positives
and
false_negatives
to compute the AUC. To discretize the AUC curve, a linearly
spaced set of thresholds is used to compute pairs of recall and precision
values. The area under the ROC-curve is therefore computed using the height of
the recall values by the false positive rate, while the area under the
PR-curve is the computed using the height of the precision values by the
recall.
This value is ultimately returned as auc
, an idempotent operation that
computes the area under a discretized curve of precision versus recall values
(computed using the aforementioned variables). The num_thresholds
variable
controls the degree of discretization with larger numbers of thresholds more
closely approximating the true AUC. The quality of the approximation may vary
dramatically depending on num_thresholds
. The thresholds
parameter can be
used to manually specify thresholds which split the predictions more evenly.
For a best approximation of the real AUC, predictions
should be distributed
approximately uniformly in the range [0, 1]. The quality of the AUC
approximation may be poor if this is not the case. Setting summation_method
to 'minoring' or 'majoring' can help quantify the error in the approximation
by providing lower or upper bound estimate of the AUC.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes AUC metric.
PARAMETER | DESCRIPTION |
---|---|
num_thresholds
|
(Optional) Defaults to 10000. The number of thresholds to use when discretizing the roc curve. Values must be > 1. |
curve
|
(Optional) Specifies the name of the curve to be computed, 'ROC' [default] or 'PR' for the Precision-Recall-curve.
TYPE:
|
summation_method
|
(Optional) Specifies the Riemann summation method used. 'interpolation'
(default) applies mid-point summation scheme for
TYPE:
|
name
|
(Optional) string name of the metric instance. |
thresholds
|
(Optional) A list of floating point values to use as the
thresholds for discretizing the curve. If set, the |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
AUCCurve
¶
AUCPrecisionRecall
¶
AUCPrecisionRecall(
num_thresholds: Optional[int] = None,
summation_method: str = "interpolation",
name: Optional[str] = None,
thresholds: Optional[Union[float, List[float]]] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: AUC
Alias for AUC(curve='PR').
Initializes AUCPrecisionRecall metric.
PARAMETER | DESCRIPTION |
---|---|
num_thresholds
|
(Optional) Defaults to 10000. The number of thresholds to use when discretizing the roc curve. Values must be > 1. |
summation_method
|
(Optional) Specifies the Riemann summation method used. 'interpolation' interpolates (true/false) positives but not the ratio that is precision (see Davis & Goadrich 2006 for details); 'minoring' applies left summation for increasing intervals and right summation for decreasing intervals; 'majoring' does the opposite.
TYPE:
|
name
|
(Optional) string name of the metric instance. |
thresholds
|
(Optional) A list of floating point values to use as the
thresholds for discretizing the curve. If set, the |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
AUCSummationMethod
¶
AttributionsMetric
¶
AttributionsMetric(
create_computations_fn: Callable[
..., MetricComputations
],
**kwargs,
)
Bases: Metric
Base type for attribution metrics.
Initializes metric.
PARAMETER | DESCRIPTION |
---|---|
create_computations_fn
|
Function to create the metrics computations (e.g. mean_label, etc). This function should take the args passed to init as as input along with any of eval_config, schema, model_names, output_names, sub_keys, aggregation_type, or query_key (where needed).
TYPE:
|
**kwargs
|
Any additional kwargs to pass to create_computations_fn. These should only contain primitive types or lists/dicts of primitive types. The kwargs passed to computations have precendence over these kwargs.
DEFAULT:
|
Source code in tensorflow_model_analysis/metrics/metric_types.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
BalancedAccuracy
¶
BalancedAccuracy(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Balanced accuracy (BA).
Initializes balanced accuracy.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
Function for computing metric value from TP, TN, FP, FN values.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
BinaryAccuracy
¶
BinaryAccuracy(
threshold: Optional[float] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
name: Optional[str] = None,
)
Bases: ConfusionMatrixMetric
Calculates how often predictions match binary labels.
This metric computes the accuracy based on (TP + TN) / (TP + FP + TN + FN).
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes BinaryAccuracy metric.
PARAMETER | DESCRIPTION |
---|---|
threshold
|
(Optional) A float value in [0, 1]. The threshold is compared
with prediction values to determine the truth value of predictions
(i.e., above the threshold is |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
name
|
(Optional) string name of the metric instance. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
BinaryCrossEntropy
¶
BinaryCrossEntropy(
name: str = BINARY_CROSSENTROPY_NAME,
from_logits: bool = False,
label_smoothing: float = 0.0,
)
Bases: Metric
Calculates the binary cross entropy.
The metric computes the cross entropy when there are only two label classes (0 and 1). See definition at: https://en.wikipedia.org/wiki/Cross_entropy
Initializes binary cross entropy metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the metric.
TYPE:
|
from_logits
|
(Optional) Whether output is expected to be a logits tensor. By default, we consider that output encodes a probability distribution.
TYPE:
|
label_smoothing
|
Float in [0, 1]. If >
TYPE:
|
Source code in tensorflow_model_analysis/metrics/cross_entropy_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
BooleanFlipRates
¶
BooleanFlipRates(
threshold: float = _DEFAULT_FLIP_RATE_THRESHOLD,
flip_rate_name: str = FLIP_RATE_NAME,
neg_to_neg_flip_rate_name: str = NEG_TO_NEG_FLIP_RATE_NAME,
neg_to_pos_flip_rate_name: str = NEG_TO_POS_FLIP_RATE_NAME,
pos_to_neg_flip_rate_name: str = POS_TO_NEG_FLIP_RATE_NAME,
pos_to_pos_flip_rate_name: str = POS_TO_POS_FLIP_RATE_NAME,
)
Bases: Metric
FlipRate is the rate at which predictions between models switch.
Given a pair of models and a threshold for converting continuous model outputs into boolean predictions, this metric will produce three numbers (keyed by separate MetricKeys):
- (symmetric) flip rate: The number of times the boolean predictions don't match, regardless of the direction of the flip.
- negative-to-positive flip rate: The rate at which the baseline model's boolean prediction is negative but the candidate model's is positive.
- positive-to-negative flip rate: The rate at which the baseline model's boolean prediction is positive but the candidate model's is negative.
Initializes BooleanFlipRates metric.
PARAMETER | DESCRIPTION |
---|---|
threshold
|
The threshold to use for converting the model prediction into a boolean value that can be used for comparison between models.
TYPE:
|
flip_rate_name
|
Metric name for symmetric flip rate.
TYPE:
|
neg_to_neg_flip_rate_name
|
Metric name for the negative-to-negative flip rate.
TYPE:
|
neg_to_pos_flip_rate_name
|
Metric name for the negative-to-positive flip rate.
TYPE:
|
pos_to_neg_flip_rate_name
|
Metric name for the positive-to-negative flip rate.
TYPE:
|
pos_to_pos_flip_rate_name
|
Metric name for the positive-to-positive flip rate.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/flip_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
COCOAveragePrecision
¶
COCOAveragePrecision(
num_thresholds: Optional[int] = None,
iou_threshold: Optional[float] = None,
class_id: Optional[int] = None,
class_weight: Optional[float] = None,
area_range: Optional[Tuple[float, float]] = None,
max_num_detections: Optional[int] = None,
recalls: Optional[List[float]] = None,
num_recalls: Optional[int] = None,
name: Optional[str] = None,
labels_to_stack: Optional[List[str]] = None,
predictions_to_stack: Optional[List[str]] = None,
num_detections_key: Optional[str] = None,
allow_missing_key: bool = False,
)
Bases: Metric
Confusion matrix at thresholds.
It computes the average precision of object detections for a single class and a single iou_threshold.
Initialize average precision metric.
This metric is only used in object-detection setting. It does not support sub_key parameters due to the matching algorithm of bounding boxes.
The metric supports using multiple outputs to form the labels/predictions if the user specifies the label/predcition keys to stack. In this case, the metric is not expected to work with multi-outputs. The metric only supports multi outputs if the output of model is already pre-stacked in the expected format, i.e. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] for labels and ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'confidence scores'] for predictions.
PARAMETER | DESCRIPTION |
---|---|
num_thresholds
|
(Optional) Number of thresholds to use for calculating the matrices and finding the precision at given recall. |
iou_threshold
|
(Optional) Threholds for a detection and ground truth pair with specific iou to be considered as a match. |
class_id
|
(Optional) The class id for calculating metrics. |
class_weight
|
(Optional) The weight associated with the object class id. |
area_range
|
(Optional) The area-range for objects to be considered for metrics. |
max_num_detections
|
(Optional) The maximum number of detections for a single image. |
recalls
|
(Optional) recalls at which precisions will be calculated. |
num_recalls
|
(Optional) Used for objecth detection, the number of recalls for calculating average precision, it equally generates points bewteen 0 and 1. (Only one of recalls and num_recalls should be used). |
name
|
(Optional) string name of the metric instance. |
labels_to_stack
|
(Optional) Keys for columns to be stacked as a single numpy array as the labels. It is searched under the key labels, features and transformed features. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] |
predictions_to_stack
|
(Optional) Output names for columns to be stacked as a single numpy array as the prediction. It should be the model's output names. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id, confidence score]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'scores'] |
num_detections_key
|
(Optional) An output name in which to find the number of detections to use for evaluation for a given example. It does nothing if predictions_to_stack is not set. The value for this output should be a scalar value or a single-value tensor. The stacked predicitions will be truncated with the specified number of detections. |
allow_missing_key
|
(Optional) If true, the preprocessor will return empty array instead of raising errors.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/object_detection_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
COCOAverageRecall
¶
COCOAverageRecall(
iou_thresholds: Optional[List[float]] = None,
class_id: Optional[int] = None,
class_weight: Optional[float] = None,
area_range: Optional[Tuple[float, float]] = None,
max_num_detections: Optional[int] = None,
name: Optional[str] = None,
labels_to_stack: Optional[List[str]] = None,
predictions_to_stack: Optional[List[str]] = None,
num_detections_key: Optional[str] = None,
allow_missing_key: bool = False,
)
Bases: Metric
Average recall metric for object detection.
It computes the average precision metric for object detections for a single class. It averages MaxRecall metric over mulitple IoU thresholds.
Initializes average recall metric.
This metric is only used in object-detection setting. It does not support sub_key parameters due to the matching algorithm of bounding boxes.
The metric supports using multiple outputs to form the labels/predictions if the user specifies the label/predcition keys to stack. In this case, the metric is not expected to work with multi-outputs. The metric only supports multi outputs if the output of model is already pre-stacked in the expected format, i.e. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] for labels and ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'confidence scores'] for predictions.
PARAMETER | DESCRIPTION |
---|---|
iou_thresholds
|
(Optional) Threholds for a detection and ground truth pair with specific iou to be considered as a match. |
class_id
|
(Optional) The class ids for calculating metrics. |
class_weight
|
(Optional) The weight associated with the object class ids. If it is provided, it should have the same length as class_ids. |
area_range
|
(Optional) The area-range for objects to be considered for metrics. |
max_num_detections
|
(Optional) The maximum number of detections for a single image. |
name
|
(Optional) Metric name. |
labels_to_stack
|
(Optional) Keys for columns to be stacked as a single numpy array as the labels. It is searched under the key labels, features and transformed features. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] |
predictions_to_stack
|
(Optional) Output names for columns to be stacked as a single numpy array as the prediction. It should be the model's output names. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id, confidence score]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'scores'] |
num_detections_key
|
(Optional) An output name in which to find the number of detections to use for evaluation for a given example. It does nothing if predictions_to_stack is not set. The value for this output should be a scalar value or a single-value tensor. The stacked predicitions will be truncated with the specified number of detections. |
allow_missing_key
|
(Optional) If true, the preprocessor will return empty array instead of raising errors.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/object_detection_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
COCOMeanAveragePrecision
¶
COCOMeanAveragePrecision(
num_thresholds: Optional[int] = None,
iou_thresholds: Optional[List[float]] = None,
class_ids: Optional[List[int]] = None,
class_weights: Optional[List[float]] = None,
area_range: Optional[Tuple[float, float]] = None,
max_num_detections: Optional[int] = None,
recalls: Optional[List[float]] = None,
num_recalls: Optional[int] = None,
name: Optional[str] = None,
labels_to_stack: Optional[List[str]] = None,
predictions_to_stack: Optional[List[str]] = None,
num_detections_key: Optional[str] = None,
allow_missing_key: bool = False,
)
Bases: Metric
Mean average precision for object detections.
It calculates the mean average precision metric for object detections. It averages COCOAveragePrecision over multiple classes and IoU thresholds.
Initializes mean average precision metric.
This metric is only used in object-detection setting. It does not support sub_key parameters due to the matching algorithm of bounding boxes.
The metric supports using multiple outputs to form the labels/predictions if the user specifies the label/predcition keys to stack. In this case, the metric is not expected to work with multi-outputs. The metric only supports multi outputs if the output of model is already pre-stacked in the expected format, i.e. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] for labels and ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'confidence scores'] for predictions.
PARAMETER | DESCRIPTION |
---|---|
num_thresholds
|
(Optional) Number of thresholds to use for calculating the matrices and finding the precision at given recall. |
iou_thresholds
|
(Optional) Threholds for a detection and ground truth pair with specific iou to be considered as a match. |
class_ids
|
(Optional) The class ids for calculating metrics. |
class_weights
|
(Optional) The weight associated with the object class ids. If it is provided, it should have the same length as class_ids. |
area_range
|
(Optional) The area-range for objects to be considered for metrics. |
max_num_detections
|
(Optional) The maximum number of detections for a single image. |
recalls
|
(Optional) recalls at which precisions will be calculated. |
num_recalls
|
(Optional) Used for objecth detection, the number of recalls for calculating average precision, it equally generates points bewteen 0 and 1. (Only one of recalls and num_recalls should be used). |
name
|
(Optional) Metric name. |
labels_to_stack
|
(Optional) Keys for columns to be stacked as a single numpy array as the labels. It is searched under the key labels, features and transformed features. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] |
predictions_to_stack
|
(Optional) Output names for columns to be stacked as a single numpy array as the prediction. It should be the model's output names. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id, confidence score]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'scores'] |
num_detections_key
|
(Optional) An output name in which to find the number of detections to use for evaluation for a given example. It does nothing if predictions_to_stack is not set. The value for this output should be a scalar value or a single-value tensor. The stacked predicitions will be truncated with the specified number of detections. |
allow_missing_key
|
(Optional) If true, the preprocessor will return empty array instead of raising errors.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/object_detection_metrics.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
COCOMeanAverageRecall
¶
COCOMeanAverageRecall(
iou_thresholds: Optional[List[float]] = None,
class_ids: Optional[List[int]] = None,
class_weights: Optional[List[float]] = None,
area_range: Optional[Tuple[float, float]] = None,
max_num_detections: Optional[int] = None,
name: Optional[str] = None,
labels_to_stack: Optional[List[str]] = None,
predictions_to_stack: Optional[List[str]] = None,
num_detections_key: Optional[str] = None,
allow_missing_key: bool = False,
)
Bases: Metric
Mean Average recall metric for object detection.
It computes the mean average precision metric for object detections for a single class. It averages COCOAverageRecall metric over mulitple classes.
Initializes average recall metric.
This metric is only used in object-detection setting. It does not support sub_key parameters due to the matching algorithm of bounding boxes.
The metric supports using multiple outputs to form the labels/predictions if the user specifies the label/predcition keys to stack. In this case, the metric is not expected to work with multi-outputs. The metric only supports multi outputs if the output of model is already pre-stacked in the expected format, i.e. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] for labels and ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'confidence scores'] for predictions.
PARAMETER | DESCRIPTION |
---|---|
iou_thresholds
|
(Optional) Threholds for a detection and ground truth pair with specific iou to be considered as a match. |
class_ids
|
(Optional) The class ids for calculating metrics. |
class_weights
|
(Optional) The weight associated with the object class ids. If it is provided, it should have the same length as class_ids. |
area_range
|
(Optional) The area-range for objects to be considered for metrics. |
max_num_detections
|
(Optional) The maximum number of detections for a single image. |
name
|
(Optional) Metric name. |
labels_to_stack
|
(Optional) Keys for columns to be stacked as a single numpy array as the labels. It is searched under the key labels, features and transformed features. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] |
predictions_to_stack
|
(Optional) Output names for columns to be stacked as a single numpy array as the prediction. It should be the model's output names. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id, confidence score]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'scores'] |
num_detections_key
|
(Optional) An output name in which to find the number of detections to use for evaluation for a given example. It does nothing if predictions_to_stack is not set. The value for this output should be a scalar value or a single-value tensor. The stacked predicitions will be truncated with the specified number of detections. |
allow_missing_key
|
(Optional) If true, the preprocessor will return empty array instead of raising errors.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/object_detection_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
Calibration
¶
Calibration(name: str = CALIBRATION_NAME)
Bases: Metric
Calibration.
Calibration in this context is defined as the total weighted predictions / total weighted labels.
Initializes calibration.
PARAMETER | DESCRIPTION |
---|---|
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/calibration.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
CalibrationPlot
¶
CalibrationPlot(
num_buckets: int = DEFAULT_NUM_BUCKETS,
left: Optional[float] = None,
right: Optional[float] = None,
name: str = CALIBRATION_PLOT_NAME,
)
Bases: Metric
Calibration plot.
Initializes calibration plot.
PARAMETER | DESCRIPTION |
---|---|
num_buckets
|
Number of buckets to use when creating the plot. Defaults to 1000.
TYPE:
|
left
|
Left boundary of plot. Defaults to 0.0 when a schema is not provided. |
right
|
Right boundary of plot. Defaults to 1.0 when a schema is not provided. |
name
|
Plot name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/calibration_plot.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
CategoricalCrossEntropy
¶
CategoricalCrossEntropy(
name: str = CATEGORICAL_CROSSENTROPY_NAME,
from_logits: bool = False,
label_smoothing: float = 0.0,
)
Bases: Metric
Calculates the categorical cross entropy.
The metric computes the cross entropy when there are multiple classes. It outputs a numpy array.
Initializes categorical cross entropy metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the metric.
TYPE:
|
from_logits
|
(Optional) Whether output is expected to be a logits tensor. By default, we consider that output encodes a probability distribution.
TYPE:
|
label_smoothing
|
Float in [0, 1]. If >
TYPE:
|
Source code in tensorflow_model_analysis/metrics/cross_entropy_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
CoefficientOfDiscrimination
¶
CoefficientOfDiscrimination(
name: str = COEFFICIENT_OF_DISCRIMINATION_NAME,
)
Bases: Metric
Coefficient of discrimination metric.
The coefficient of discrimination measures the differences between the average prediction for the positive examples and the average prediction for the negative examples.
The formula is: AVG(pred | label = 1) - AVG(pred | label = 0) More details can be found in the following paper: https://www.tandfonline.com/doi/abs/10.1198/tast.2009.08210
Initializes coefficient of discrimination metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/tjur_discrimination.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
ConfusionMatrixAtThresholds
¶
ConfusionMatrixAtThresholds(
thresholds: List[float],
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: Metric
Confusion matrix at thresholds.
Initializes confusion matrix at thresholds.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
Thresholds to use for confusion matrix. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
ConfusionMatrixPlot
¶
ConfusionMatrixPlot(
num_thresholds: int = DEFAULT_NUM_THRESHOLDS,
name: str = CONFUSION_MATRIX_PLOT_NAME,
**kwargs,
)
Bases: Metric
Confusion matrix plot.
Initializes confusion matrix plot.
PARAMETER | DESCRIPTION |
---|---|
num_thresholds
|
Number of thresholds to use when discretizing the curve. Values must be > 1. Defaults to 1000.
TYPE:
|
name
|
Metric name.
TYPE:
|
**kwargs
|
(Optional) Additional args to pass along to init (and eventually on to _confusion_matrix_plot). These kwargs are useful for subclasses to pass information from their init to the create_computation_fn.
DEFAULT:
|
Source code in tensorflow_model_analysis/metrics/confusion_matrix_plot.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
DerivedMetricComputation
¶
Bases: NamedTuple('DerivedMetricComputation', [('keys', List[MetricKey]), ('result', Callable)])
DerivedMetricComputation derives its result from other computations.
When creating derived metric computations it is recommended (but not required) that the underlying MetricComputations that they depend on are defined at the same time. This is to avoid having to pre-construct and pass around all the required dependencies in order to construct a derived metric. The evaluation pipeline is responsible for de-duplicating overlapping MetricComputations so that only one computation is actually run.
A DerivedMetricComputation is uniquely identified by the combination of the result function's name and the keys. Duplicate computations will be removed automatically.
ATTRIBUTE | DESCRIPTION |
---|---|
keys |
List of metric keys associated with derived computation. If the keys are defined as part of the computation then this may be empty in which case only the result function name will be used for identifying computation uniqueness.
|
result |
Function (called per slice) to compute the result using the results of other metric computations.
|
DiagnosticOddsRatio
¶
DiagnosticOddsRatio(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Diagnostic odds ratio (DOR).
Initializes diagnostic odds ratio.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
Function for computing metric value from TP, TN, FP, FN values.
ExactMatch
¶
Bases: Metric
Exact Match Metric.
Initializes exact match metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the metric to use.
TYPE:
|
convert_to
|
The conversion to perform before checking equality. |
Source code in tensorflow_model_analysis/metrics/exact_match.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
ExampleCount
¶
ExampleCount(name: str = EXAMPLE_COUNT_NAME)
Bases: Metric
Example count.
Note that although the example_count is independent of the model, this metric will be associated with a model for consistency with other metrics.
Initializes example count.
PARAMETER | DESCRIPTION |
---|---|
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/example_count.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Always disable confidence intervals for ExampleCount.
Confidence intervals capture uncertainty in a metric if it were computed on more examples. For ExampleCount, this sort of uncertainty is not meaningful, so confidence intervals are disabled.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
F1Score
¶
F1Score(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
F1 score.
Initializes F1 score.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
Function for computing metric value from TP, TN, FP, FN values.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
FN
¶
FN(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: FalseNegatives
Alias for FalseNegatives.
Initializes FN metric.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
FNR
¶
FNR(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: MissRate
Alias for MissRate.
Initializes FNR metric.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
FP
¶
FP(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: FalsePositives
Alias for FalsePositives.
Initializes FP metric.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
FPR
¶
FPR(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: FallOut
Alias for FallOut.
Initializes FPR metric.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
FallOut
¶
FallOut(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Fall-out (FPR).
Initializes fall-out metric.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use for fall-out. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
FalseDiscoveryRate
¶
FalseDiscoveryRate(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
False discovery rate (FDR).
Initializes false discovery rate.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
FalseNegatives
¶
FalseNegatives(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Calculates the number of false negatives.
If sample_weight
is given, calculates the sum of the weights of false
negatives.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes FalseNegatives metric.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Defaults to [0.5]. A float value or a python
list/tuple of float threshold values in [0, 1]. A threshold is compared
with prediction values to determine the truth value of predictions
(i.e., above the threshold is |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
FalseOmissionRate
¶
FalseOmissionRate(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
False omission rate (FOR).
Initializes false omission rate.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
FalsePositives
¶
FalsePositives(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Calculates the number of false positives.
If sample_weight
is given, calculates the sum of the weights of false
positives.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes FalsePositives metric.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Defaults to [0.5]. A float value or a python
list/tuple of float threshold values in [0, 1]. A threshold is compared
with prediction values to determine the truth value of predictions
(i.e., above the threshold is |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
FowlkesMallowsIndex
¶
FowlkesMallowsIndex(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Fowlkes-Mallows index (FM).
Initializes fowlkes-mallows index.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
Function for computing metric value from TP, TN, FP, FN values.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Informedness
¶
Informedness(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Informedness or bookmaker informedness (BM).
Initializes informedness.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
Function for computing metric value from TP, TN, FP, FN values.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Markedness
¶
Markedness(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Markedness (MK) or deltaP.
Initializes markedness.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
Function for computing metric value from TP, TN, FP, FN values.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
MatthewsCorrelationCoefficient
¶
MatthewsCorrelationCoefficient(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Matthews corrrelation coefficient (MCC).
Initializes matthews corrrelation coefficient.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
Function for computing metric value from TP, TN, FP, FN values.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
MaxRecall
¶
MaxRecall(
top_k: Optional[int] = None,
class_id: Optional[int] = None,
name: Optional[str] = None,
**kwargs,
)
Bases: Recall
Computes the max recall of the predictions with respect to the labels.
The metric uses true positives and false negatives to compute recall by dividing the true positives by the sum of true positives and false negatives.
Effectively the recall at threshold = epsilon(1.0e-12). It is equilvalent to the recall defined in COCO metrics.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes MaxRecall metrics, it calculates the maximum recall.
PARAMETER | DESCRIPTION |
---|---|
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
name
|
(Optional) string name of the metric instance. |
**kwargs
|
(Optional) Additional args to pass along to init (and eventually on to _metric_computation and _metric_value)
DEFAULT:
|
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
Mean
¶
Mean(
feature_key_path: _KeyPath,
example_weights_key_path: Optional[_KeyPath] = None,
name: Optional[str] = None,
)
Bases: Metric
Mean metric.
Initializes mean metric.
PARAMETER | DESCRIPTION |
---|---|
feature_key_path
|
key path to feature to calculate the mean of.
TYPE:
|
example_weights_key_path
|
key path to example weights.
TYPE:
|
name
|
Metric base name. |
Source code in tensorflow_model_analysis/metrics/stats.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
MeanAbsoluteAttributions
¶
MeanAbsoluteAttributions(
name: str = MEAN_ABSOLUTE_ATTRIBUTIONS_NAME,
)
Bases: AttributionsMetric
Mean aboslute attributions metric.
Initializes mean absolute attributions metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
Attribution metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/attributions.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
MeanAbsoluteError
¶
MeanAbsoluteError(
name: str = MEAN_ABSOLUTE_ERROR_NAME, **kwargs
)
Bases: Metric
Calculates the mean of absolute error between labels and predictions.
Formula: error = abs(label - prediction)
The metric computes the mean of absolute error between labels and predictions. The labels and predictions should be floats.
Initializes mean regression error metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the metric.
TYPE:
|
**kwargs
|
Additional named keyword arguments.
DEFAULT:
|
Source code in tensorflow_model_analysis/metrics/mean_regression_error.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
MeanAbsolutePercentageError
¶
MeanAbsolutePercentageError(
name: str = MEAN_ABSOLUTE_PERCENTAGE_ERROR_NAME,
**kwargs,
)
Bases: Metric
Calculates the mean of absolute percentage error.
Formula: error = 100 * abs( (label - prediction) / label )
The metric computes the mean of absolute percentage error between labels and predictions. The labels and predictions should be floats.
Initializes mean regression error metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the metric.
TYPE:
|
**kwargs
|
Additional named keyword arguments.
DEFAULT:
|
Source code in tensorflow_model_analysis/metrics/mean_regression_error.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
MeanAttributions
¶
MeanAttributions(name: str = MEAN_ATTRIBUTIONS_NAME)
Bases: AttributionsMetric
Mean attributions metric.
Initializes mean attributions metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
Attribution metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/attributions.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
MeanLabel
¶
MeanLabel(name: str = MEAN_LABEL_NAME)
Bases: Metric
Mean label.
Initializes mean label.
PARAMETER | DESCRIPTION |
---|---|
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/calibration.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
MeanPrediction
¶
MeanPrediction(name: str = MEAN_PREDICTION_NAME)
Bases: Metric
Mean prediction.
Initializes mean prediction.
PARAMETER | DESCRIPTION |
---|---|
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/calibration.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
MeanSquaredError
¶
MeanSquaredError(
name: str = MEAN_SQUARED_ERROR_NAME, **kwargs
)
Bases: Metric
Calculates the mean of squared error between labels and predictions.
Formula: error = L2_norm(label - prediction)**2
The metric computes the mean of squared error (square of L2 norm) between labels and predictions. The labels and predictions could be arrays of arbitrary dimensions. Their dimension should match.
Initializes mean regression error metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the metric.
TYPE:
|
**kwargs
|
Additional named keyword arguments.
DEFAULT:
|
Source code in tensorflow_model_analysis/metrics/mean_regression_error.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
MeanSquaredLogarithmicError
¶
MeanSquaredLogarithmicError(
name: str = MEAN_SQUARED_LOGARITHMIC_ERROR_NAME,
**kwargs,
)
Bases: Metric
Calculates the mean of squared logarithmic error.
Formula: error = L2_norm(log(label + 1) - log(prediction + 1))**2 Note: log of an array will be elementwise, i.e. log([x1, x2]) = [log(x1), log(x2)]
The metric computes the mean of squared logarithmic error (square of L2 norm) between labels and predictions. The labels and predictions could be arrays of arbitrary dimensions. Their dimension should match.
Initializes mean regression error metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the metric.
TYPE:
|
**kwargs
|
Additional named keyword arguments.
DEFAULT:
|
Source code in tensorflow_model_analysis/metrics/mean_regression_error.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
Metric
¶
Metric(
create_computations_fn: Callable[
..., MetricComputations
],
**kwargs,
)
Metric wraps a set of metric computations.
This class exists to provide similarity between tfma.metrics.Metric and tf.keras.metics.Metric.
Calling computations creates the metric computations. The parameters passed to init will be combined with the parameters passed to the computations method. This allows some of the parameters (e.g. model_names, output_names, sub_keys) to be set at the time the computations are created instead of when the metric is defined.
Initializes metric.
PARAMETER | DESCRIPTION |
---|---|
create_computations_fn
|
Function to create the metrics computations (e.g. mean_label, etc). This function should take the args passed to init as as input along with any of eval_config, schema, model_names, output_names, sub_keys, aggregation_type, or query_key (where needed).
TYPE:
|
**kwargs
|
Any additional kwargs to pass to create_computations_fn. These should only contain primitive types or lists/dicts of primitive types. The kwargs passed to computations have precendence over these kwargs.
DEFAULT:
|
Source code in tensorflow_model_analysis/metrics/metric_types.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
MetricComputation
¶
Bases: NamedTuple('MetricComputation', [('keys', List[MetricKey]), ('preprocessors', List[Preprocessor]), ('combiner', CombineFn)])
MetricComputation represents one or more metric computations.
The preprocessors are called with a PCollection of extracts (or list of extracts if query_key is used) to compute the initial combiner input state which is then passed to the combiner. This needs to be done in two steps because slicing happens between the call to the preprocessors and the combiner and this state may end up in multiple slices so we want the representation to be as efficient as possible. If the preprocessors are None, then StandardMetricInputs will be passed.
A MetricComputation is uniquely identified by the combination of the combiner's name and the keys. Duplicate computations will be removed automatically.
ATTRIBUTE | DESCRIPTION |
---|---|
keys |
List of metric keys associated with computation. If the keys are defined as part of the computation then this may be empty in which case only the combiner name will be used for identifying computation uniqueness.
|
preprocessors |
Takes a extracts (or a list of extracts) as input (which typically will contain labels, predictions, example weights, and optionally features) and should return the initial state that the combiner will use as input. The output of a processor should only contain information needed by the combiner.
|
combiner |
Takes preprocessor output as input and outputs a tuple: (slice, metric results). The metric results should be a dict from MetricKey to value (float, int, distribution, ...).
|
MetricKey
¶
Bases: NamedTuple('MetricKey', [('name', str), ('model_name', str), ('output_name', str), ('sub_key', Optional[SubKey]), ('aggregation_type', Optional[AggregationType]), ('example_weighted', Optional[bool]), ('is_diff', bool)])
A MetricKey uniquely identifies a metric.
ATTRIBUTE | DESCRIPTION |
---|---|
name |
Metric name. Names starting with '_' are private and will be filtered from the final results. Names starting with two underscores, '__' are reserved for internal use.
|
model_name |
Optional model name (if multi-model evaluation).
|
output_name |
Optional output name (if multi-output model type).
|
sub_key |
Optional sub key.
|
aggregation_type |
Optional Aggregation type.
|
example_weighted |
Indicates whether this metric was weighted by examples.
|
is_diff |
Optional flag to indicate whether this metrics is a diff metric.
|
Functions¶
from_proto
staticmethod
¶
from_proto(pb: MetricKey) -> MetricKey
Configures class from proto.
Source code in tensorflow_model_analysis/metrics/metric_types.py
make_baseline_key
¶
to_proto
¶
Converts key to proto.
Source code in tensorflow_model_analysis/metrics/metric_types.py
MinLabelPosition
¶
Bases: Metric
Min label position metric.
Calculates the least index in a query which has a positive label. The final returned value is the weighted average over all queries in the evaluation set which have at least one labeled entry. Note, ranking is indexed from one, so the optimal value for this metric is one. If there are no labeled rows in the evaluation set, the final output will be zero.
This is a query/ranking based metric so a query_key must also be provided in the associated metrics spec.
Initializes min label position metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
Metric name.
DEFAULT:
|
label_key
|
Optional label key to override default label. |
Source code in tensorflow_model_analysis/metrics/min_label_position.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
MissRate
¶
MissRate(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Miss rate (FNR).
Initializes miss rate metric.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use for miss rate. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
MultiClassConfusionMatrixAtThresholds
¶
MultiClassConfusionMatrixAtThresholds(
thresholds: Optional[List[float]] = None,
name: str = MULTI_CLASS_CONFUSION_MATRIX_AT_THRESHOLDS_NAME,
)
Bases: Metric
Multi-class confusion matrix metrics at thresholds.
Computes weighted example counts for all combinations of actual / (top) predicted classes.
The inputs are assumed to contain a single positive label per example (i.e. only one class can be true at a time) while the predictions are assumed to sum to 1.0.
Initializes multi-class confusion matrix.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
Optional thresholds, defaults to 0.5 if not specified. If the top prediction is less than a threshold then the associated example will be assumed to have no prediction associated with it (the predicted_class_id will be set to NO_PREDICTED_CLASS_ID). |
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/multi_class_confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
MultiClassConfusionMatrixPlot
¶
MultiClassConfusionMatrixPlot(
thresholds: Optional[List[float]] = None,
num_thresholds: Optional[int] = None,
name: str = MULTI_CLASS_CONFUSION_MATRIX_PLOT_NAME,
)
Bases: Metric
Multi-class confusion matrix plot.
Computes weighted example counts for all combinations of actual / (top) predicted classes.
The inputs are assumed to contain a single positive label per example (i.e. only one class can be true at a time) while the predictions are assumed to sum to 1.0.
Initializes multi-class confusion matrix.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
Optional thresholds. If the top prediction is less than a threshold then the associated example will be assumed to have no prediction associated with it (the predicted_class_id will be set to tfma.metrics.NO_PREDICTED_CLASS_ID). Only one of either thresholds or num_thresholds should be used. If both are unset, then [0.0] will be assumed. |
num_thresholds
|
Number of thresholds to use. The thresholds will be evenly spaced between 0.0 and 1.0 and inclusive of the boundaries (i.e. to configure the thresholds to [0.0, 0.25, 0.5, 0.75, 1.0], the parameter should be set to 5). Only one of either thresholds or num_thresholds should be used. |
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/multi_class_confusion_matrix_plot.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
MultiLabelConfusionMatrixPlot
¶
MultiLabelConfusionMatrixPlot(
thresholds: Optional[List[float]] = None,
num_thresholds: Optional[int] = None,
name: str = MULTI_LABEL_CONFUSION_MATRIX_PLOT_NAME,
)
Bases: Metric
Multi-label confusion matrix.
For each actual class (positive label) a confusion matrix is computed for each class based on the associated predicted values such that:
TP = positive_prediction_class_label & positive_prediction TN = negative_prediction_class_label & negative_prediction FP = negative_prediction_class_label & positive_prediction FN = positive_prediction_class_label & negative_prediction
For example, given classes 0, 1 and a given threshold, the following matrices will be computed:
Actual: class_0 Predicted: class_0 TP = is_class_0 & is_class_0 & predict_class_0 TN = is_class_0 & not_class_0 & predict_not_class_0 FN = is_class_0 & is_class_0 & predict_not_class_0 FP = is_class_0 & not_class_0 & predict_class_0 Actual: class_0 Predicted: class_1 TP = is_class_0 & is_class_1 & predict_class_1 TN = is_class_0 & not_class_1 & predict_not_class_1 FN = is_class_0 & is_class_1 & predict_not_class_1 FP = is_class_0 & not_class_1 & predict_class_1 Actual: class_1 Predicted: class_0 TP = is_class_1 & is_class_0 & predict_class_0 TN = is_class_1 & not_class_0 & predict_not_class_0 FN = is_class_1 & is_class_0 & predict_not_class_0 FP = is_class_1 & not_class_0 & predict_class_0 Actual: class_1 Predicted: class_1 TP = is_class_1 & is_class_1 & predict_class_1 TN = is_class_1 & not_class_1 & predict_not_class_1 FN = is_class_1 & is_class_1 & predict_not_class_1 FP = is_class_1 & not_class_1 & predict_class_1
Note that unlike the multi-class confusion matrix, the inputs are assumed to be multi-label whereby the predictions may not necessarily sum to 1.0 and multiple classes can be true as the same time.
Initializes multi-label confusion matrix.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
Optional thresholds. Only one of either thresholds or num_thresholds should be used. If both are unset, then [0.5] will be assumed. |
num_thresholds
|
Number of thresholds to use. The thresholds will be evenly spaced between 0.0 and 1.0 and inclusive of the boundaries (i.e. to configure the thresholds to [0.0, 0.25, 0.5, 0.75, 1.0], the parameter should be set to 5). Only one of either thresholds or num_thresholds should be used. |
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/multi_label_confusion_matrix_plot.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
NDCG
¶
Bases: Metric
NDCG (normalized discounted cumulative gain) metric.
Calculates NDCG@k for a given set of top_k values calculated from a list of gains (relevance scores) that are sorted based on the associated predictions. The top_k_list can be passed as part of the NDCG metric config or using tfma.MetricsSpec.binarize.top_k_list if configuring multiple top_k metrics. The gain (relevance score) is determined from the value stored in the 'gain_key' feature. The value of NDCG@k returned is a weighted average of NDCG@k over the set of queries using the example weights.
NDCG@k = (DCG@k for the given rank)/(DCG@k DCG@k = sum_{i=1}^k gain_i/log_2(i+1), where gain_i is the gain (relevance score) of the i^th ranked response, indexed from 1.
This is a query/ranking based metric so a query_key must also be provided in the associated tfma.MetricsSpec.
Initializes NDCG.
PARAMETER | DESCRIPTION |
---|---|
gain_key
|
Key of feature in features dictionary that holds gain values.
TYPE:
|
top_k_list
|
Values for top k. This can also be set using the tfma.MetricsSpec.binarize.top_k_list associated with the metric. |
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/ndcg.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
NPV
¶
NPV(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: NegativePredictiveValue
Alias for NegativePredictiveValue.
Initializes PPV metric.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
NegativeLikelihoodRatio
¶
NegativeLikelihoodRatio(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Negative likelihood ratio (LR-).
Initializes negative likelihood ratio.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
Function for computing metric value from TP, TN, FP, FN values.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
NegativePredictiveValue
¶
NegativePredictiveValue(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Negative predictive value (NPV).
Initializes negative predictive value.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
ObjectDetectionConfusionMatrixPlot
¶
ObjectDetectionConfusionMatrixPlot(
num_thresholds: int = DEFAULT_NUM_THRESHOLDS,
name: str = CONFUSION_MATRIX_PLOT_NAME,
iou_threshold: Optional[float] = None,
class_id: Optional[int] = None,
class_weight: Optional[float] = None,
area_range: Optional[Tuple[float, float]] = None,
max_num_detections: Optional[int] = None,
labels_to_stack: Optional[List[str]] = None,
predictions_to_stack: Optional[List[str]] = None,
num_detections_key: Optional[str] = None,
allow_missing_key: bool = False,
)
Bases: ConfusionMatrixPlot
Object Detection Confusion matrix plot.
Initializes confusion matrix plot for object detection.
The metric supports using multiple outputs to form the labels/predictions if the user specifies the label/predcition keys to stack. In this case, the metric is not expected to work with multi-outputs. The metric only supports multi outputs if the output of model is already pre-stacked in the expected format, i.e. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] for labels and ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'confidence scores'] for predictions.
PARAMETER | DESCRIPTION |
---|---|
num_thresholds
|
Number of thresholds to use when discretizing the curve. Values must be > 1. Defaults to 1000.
TYPE:
|
name
|
Metric name.
TYPE:
|
iou_threshold
|
(Optional) Thresholds for a detection and ground truth pair with specific iou to be considered as a match. Default to 0.5 |
class_id
|
(Optional) The class id for calculating metrics. |
class_weight
|
(Optional) The weight associated with the object class id. |
area_range
|
(Optional) A tuple (inclusive) representing the area-range for objects to be considered for metrics. Default to (0, inf). |
max_num_detections
|
(Optional) The maximum number of detections for a single image. Default to None. |
labels_to_stack
|
(Optional) Keys for columns to be stacked as a single numpy array as the labels. It is searched under the key labels, features and transformed features. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] |
predictions_to_stack
|
(Optional) Output names for columns to be stacked as a single numpy array as the prediction. It should be the model's output names. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id, confidence score]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'scores'] |
num_detections_key
|
(Optional) An output name in which to find the number of detections to use for evaluation for a given example. It does nothing if predictions_to_stack is not set. The value for this output should be a scalar value or a single-value tensor. The stacked predicitions will be truncated with the specified number of detections. |
allow_missing_key
|
(Optional) If true, the preprocessor will return empty array instead of raising errors.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/object_detection_confusion_matrix_plot.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
ObjectDetectionMaxRecall
¶
ObjectDetectionMaxRecall(
name: Optional[str] = None,
iou_threshold: Optional[float] = None,
class_id: Optional[int] = None,
class_weight: Optional[float] = None,
area_range: Optional[Tuple[float, float]] = None,
max_num_detections: Optional[int] = None,
labels_to_stack: Optional[List[str]] = None,
predictions_to_stack: Optional[List[str]] = None,
num_detections_key: Optional[str] = None,
allow_missing_key: bool = False,
)
Bases: MaxRecall
Computes the max recall of the predictions with respect to the labels.
The metric uses true positives and false negatives to compute recall by dividing the true positives by the sum of true positives and false negatives.
Effectively the recall at threshold = epsilon(1.0e-12). It is equilvalent to the recall defined in COCO metrics.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes MaxRecall metrics, it calculates the maximum recall.
The metric supports using multiple outputs to form the labels/predictions if the user specifies the label/predcition keys to stack. In this case, the metric is not expected to work with multi-outputs. The metric only supports multi outputs if the output of model is already pre-stacked in the expected format, i.e. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] for labels and ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'confidence scores'] for predictions.
PARAMETER | DESCRIPTION |
---|---|
name
|
(Optional) string name of the metric instance. |
iou_threshold
|
(Optional) Thresholds for a detection and ground truth pair with specific iou to be considered as a match. Default to 0.5 |
class_id
|
(Optional) The class id for calculating metrics. |
class_weight
|
(Optional) The weight associated with the object class id. |
area_range
|
(Optional) A tuple (inclusive) representing the area-range for objects to be considered for metrics. Default to (0, inf). |
max_num_detections
|
(Optional) The maximum number of detections for a single image. Default to None. |
labels_to_stack
|
(Optional) Keys for columns to be stacked as a single numpy array as the labels. It is searched under the key labels, features and transformed features. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] |
predictions_to_stack
|
(Optional) Output names for columns to be stacked as a single numpy array as the prediction. It should be the model's output names. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id, confidence score]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'scores'] |
num_detections_key
|
(Optional) An output name in which to find the number of detections to use for evaluation for a given example. It does nothing if predictions_to_stack is not set. The value for this output should be a scalar value or a single-value tensor. The stacked predicitions will be truncated with the specified number of detections. |
allow_missing_key
|
(Optional) If true, the preprocessor will return empty array instead of raising errors.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/object_detection_confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
ObjectDetectionPrecision
¶
ObjectDetectionPrecision(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
iou_threshold: Optional[float] = None,
class_id: Optional[int] = None,
class_weight: Optional[float] = None,
area_range: Optional[Tuple[float, float]] = None,
max_num_detections: Optional[int] = None,
labels_to_stack: Optional[List[str]] = None,
predictions_to_stack: Optional[List[str]] = None,
num_detections_key: Optional[str] = None,
allow_missing_key: bool = False,
)
Bases: Precision
Computes the precision of the predictions with respect to the labels.
The metric uses true positives and false positives to compute precision by dividing the true positives by the sum of true positives and false positives.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes Recall metric.
The metric supports using multiple outputs to form the labels/predictions if the user specifies the label/predcition keys to stack. In this case, the metric is not expected to work with multi-outputs. The metric only supports multi outputs if the output of model is already pre-stacked in the expected format, i.e. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] for labels and ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'confidence scores'] for predictions.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) A float value or a python list/tuple of float
threshold values in [0, 1]. A threshold is compared with prediction
values to determine the truth value of predictions (i.e., above the
threshold is |
name
|
(Optional) string name of the metric instance. |
iou_threshold
|
(Optional) Thresholds for a detection and ground truth pair with specific iou to be considered as a match. Default to 0.5 |
class_id
|
(Optional) The class id for calculating metrics. |
class_weight
|
(Optional) The weight associated with the object class id. |
area_range
|
(Optional) A tuple (inclusive) representing the area-range for objects to be considered for metrics. Default to (0, inf). |
max_num_detections
|
(Optional) The maximum number of detections for a single image. Default to None. |
labels_to_stack
|
(Optional) Keys for columns to be stacked as a single numpy array as the labels. It is searched under the key labels, features and transformed features. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] |
predictions_to_stack
|
(Optional) Output names for columns to be stacked as a single numpy array as the prediction. It should be the model's output names. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id, confidence score]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'scores'] |
num_detections_key
|
(Optional) An output name in which to find the number of detections to use for evaluation for a given example. It does nothing if predictions_to_stack is not set. The value for this output should be a scalar value or a single-value tensor. The stacked predicitions will be truncated with the specified number of detections. |
allow_missing_key
|
(Optional) If true, the preprocessor will return empty array instead of raising errors.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/object_detection_confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
ObjectDetectionPrecisionAtRecall
¶
ObjectDetectionPrecisionAtRecall(
recall: Union[float, List[float]],
thresholds: Optional[List[float]] = None,
num_thresholds: Optional[int] = None,
name: Optional[str] = None,
iou_threshold: Optional[float] = None,
class_id: Optional[int] = None,
class_weight: Optional[float] = None,
area_range: Optional[Tuple[float, float]] = None,
max_num_detections: Optional[int] = None,
labels_to_stack: Optional[List[str]] = None,
predictions_to_stack: Optional[List[str]] = None,
num_detections_key: Optional[str] = None,
allow_missing_key: bool = False,
)
Bases: PrecisionAtRecall
Computes best precision where recall is >= specified value.
The threshold for the given recall value is computed and used to evaluate the corresponding precision.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes PrecisionAtRecall metric.
The metric supports using multiple outputs to form the labels/predictions if the user specifies the label/predcition keys to stack. In this case, the metric is not expected to work with multi-outputs. The metric only supports multi outputs if the output of model is already pre-stacked in the expected format, i.e. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] for labels and ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'confidence scores'] for predictions.
PARAMETER | DESCRIPTION |
---|---|
recall
|
A scalar or a list of scalar values in range |
thresholds
|
(Optional) Thresholds to use for calculating the matrices. Use one of either thresholds or num_thresholds. |
num_thresholds
|
(Optional) Defaults to 1000. The number of thresholds to use for matching the given recall. |
name
|
(Optional) string name of the metric instance. |
iou_threshold
|
(Optional) Thresholds for a detection and ground truth pair with specific iou to be considered as a match. Default to 0.5 |
class_id
|
(Optional) The class id for calculating metrics. |
class_weight
|
(Optional) The weight associated with the object class id. |
area_range
|
(Optional) A tuple (inclusive) representing the area-range for objects to be considered for metrics. Default to (0, inf). |
max_num_detections
|
(Optional) The maximum number of detections for a single image. Default to None. |
labels_to_stack
|
(Optional) Keys for columns to be stacked as a single numpy array as the labels. It is searched under the key labels, features and transformed features. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] |
predictions_to_stack
|
(Optional) Output names for columns to be stacked as a single numpy array as the prediction. It should be the model's output names. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id, confidence score]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'scores'] |
num_detections_key
|
(Optional) An output name in which to find the number of detections to use for evaluation for a given example. It does nothing if predictions_to_stack is not set. The value for this output should be a scalar value or a single-value tensor. The stacked predicitions will be truncated with the specified number of detections. |
allow_missing_key
|
(Optional) If true, the preprocessor will return empty array instead of raising errors.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/object_detection_confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
ObjectDetectionRecall
¶
ObjectDetectionRecall(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
iou_threshold: Optional[float] = None,
class_id: Optional[int] = None,
class_weight: Optional[float] = None,
area_range: Optional[Tuple[float, float]] = None,
max_num_detections: Optional[int] = None,
labels_to_stack: Optional[List[str]] = None,
predictions_to_stack: Optional[List[str]] = None,
num_detections_key: Optional[str] = None,
allow_missing_key: bool = False,
)
Bases: Recall
Computes the recall of the predictions with respect to the labels.
The metric uses true positives and false negatives to compute recall by dividing the true positives by the sum of true positives and false negatives.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes Recall metric.
The metric supports using multiple outputs to form the labels/predictions if the user specifies the label/predcition keys to stack. In this case, the metric is not expected to work with multi-outputs. The metric only supports multi outputs if the output of model is already pre-stacked in the expected format, i.e. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] for labels and ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'confidence scores'] for predictions.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) A float value or a python list/tuple of float
threshold values in [0, 1]. A threshold is compared with prediction
values to determine the truth value of predictions (i.e., above the
threshold is |
name
|
(Optional) string name of the metric instance. |
iou_threshold
|
(Optional) Thresholds for a detection and ground truth pair with specific iou to be considered as a match. Default to 0.5 |
class_id
|
(Optional) The class id for calculating metrics. |
class_weight
|
(Optional) The weight associated with the object class id. |
area_range
|
(Optional) A tuple (inclusive) representing the area-range for objects to be considered for metrics. Default to (0, inf). |
max_num_detections
|
(Optional) The maximum number of detections for a single image. Default to None. |
labels_to_stack
|
(Optional) Keys for columns to be stacked as a single numpy array as the labels. It is searched under the key labels, features and transformed features. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] |
predictions_to_stack
|
(Optional) Output names for columns to be stacked as a single numpy array as the prediction. It should be the model's output names. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id, confidence score]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'scores'] |
num_detections_key
|
(Optional) An output name in which to find the number of detections to use for evaluation for a given example. It does nothing if predictions_to_stack is not set. The value for this output should be a scalar value or a single-value tensor. The stacked predicitions will be truncated with the specified number of detections. |
allow_missing_key
|
(Optional) If true, the preprocessor will return empty array instead of raising errors.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/object_detection_confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
ObjectDetectionThresholdAtRecall
¶
ObjectDetectionThresholdAtRecall(
recall: Union[float, List[float]],
thresholds: Optional[List[float]] = None,
num_thresholds: Optional[int] = None,
name: Optional[str] = None,
iou_threshold: Optional[float] = None,
class_id: Optional[int] = None,
class_weight: Optional[float] = None,
area_range: Optional[Tuple[float, float]] = None,
max_num_detections: Optional[int] = None,
labels_to_stack: Optional[List[str]] = None,
predictions_to_stack: Optional[List[str]] = None,
num_detections_key: Optional[str] = None,
allow_missing_key: bool = False,
)
Bases: ThresholdAtRecall
Computes maximum threshold where recall is >= specified value.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes ThresholdAtRecall metric.
The metric supports using multiple outputs to form the labels/predictions if the user specifies the label/predcition keys to stack. In this case, the metric is not expected to work with multi-outputs. The metric only supports multi outputs if the output of model is already pre-stacked in the expected format, i.e. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] for labels and ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'confidence scores'] for predictions.
PARAMETER | DESCRIPTION |
---|---|
recall
|
A scalar or a list of scalar values in range |
thresholds
|
(Optional) Thresholds to use for calculating the matrices. Use one of either thresholds or num_thresholds. |
num_thresholds
|
(Optional) Defaults to 1000. The number of thresholds to use for matching the given recall. |
name
|
(Optional) string name of the metric instance. |
iou_threshold
|
(Optional) Thresholds for a detection and ground truth pair with specific iou to be considered as a match. Default to 0.5 |
class_id
|
(Optional) The class id for calculating metrics. |
class_weight
|
(Optional) The weight associated with the object class id. |
area_range
|
(Optional) A tuple (inclusive) representing the area-range for objects to be considered for metrics. Default to (0, inf). |
max_num_detections
|
(Optional) The maximum number of detections for a single image. Default to None. |
labels_to_stack
|
(Optional) Keys for columns to be stacked as a single numpy array as the labels. It is searched under the key labels, features and transformed features. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id'] |
predictions_to_stack
|
(Optional) Output names for columns to be stacked as a single numpy array as the prediction. It should be the model's output names. The desired format is [left bounadary, top boudnary, right boundary, bottom boundary, class id, confidence score]. e.g. ['xmin', 'ymin', 'xmax', 'ymax', 'class_id', 'scores'] |
num_detections_key
|
(Optional) An output name in which to find the number of detections to use for evaluation for a given example. It does nothing if predictions_to_stack is not set. The value for this output should be a scalar value or a single-value tensor. The stacked predicitions will be truncated with the specified number of detections. |
allow_missing_key
|
(Optional) If true, the preprocessor will return empty array instead of raising errors.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/object_detection_confusion_matrix_metrics.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 |
|
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
PPV
¶
PPV(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: Precision
Alias for Precision.
Initializes PPV metric.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
PlotKey
¶
Bases: MetricKey
A PlotKey is a metric key that uniquely identifies a plot.
Functions¶
from_proto
staticmethod
¶
from_proto(pb: PlotKey) -> PlotKey
Configures class from proto.
Source code in tensorflow_model_analysis/metrics/metric_types.py
make_baseline_key
¶
to_proto
¶
Converts key to proto.
Source code in tensorflow_model_analysis/metrics/metric_types.py
PositiveLikelihoodRatio
¶
PositiveLikelihoodRatio(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Positive likelihood ratio (LR+).
Initializes positive likelihood ratio.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
Function for computing metric value from TP, TN, FP, FN values.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Precision
¶
Precision(
thresholds: Optional[Union[float, List[float]]] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
name: Optional[str] = None,
**kwargs,
)
Bases: ConfusionMatrixMetric
Computes the precision of the predictions with respect to the labels.
The metric uses true positives and false positives to compute precision by dividing the true positives by the sum of true positives and false positives.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes Precision metric.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) A float value or a python list/tuple of float
threshold values in [0, 1]. A threshold is compared with prediction
values to determine the truth value of predictions (i.e., above the
threshold is |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
name
|
(Optional) string name of the metric instance. |
**kwargs
|
(Optional) Additional args to pass along to init (and eventually on to _metric_computation and _metric_value).
DEFAULT:
|
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
PrecisionAtRecall
¶
PrecisionAtRecall(
recall: Union[float, List[float]],
thresholds: Optional[List[float]] = None,
num_thresholds: Optional[int] = None,
class_id: Optional[int] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
**kwargs,
)
Bases: ConfusionMatrixMetricBase
Computes best precision where recall is >= specified value.
The threshold for the given recall value is computed and used to evaluate the corresponding precision.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes PrecisionAtRecall metric.
PARAMETER | DESCRIPTION |
---|---|
recall
|
A scalar or a list of scalar values in range |
thresholds
|
(Optional) Thresholds to use for calculating the matrices. Use one of either thresholds or num_thresholds. |
num_thresholds
|
(Optional) Defaults to 1000. The number of thresholds to use for matching the given recall. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
name
|
(Optional) string name of the metric instance. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
**kwargs
|
(Optional) Additional args to pass along to init (and eventually on to _metric_computation and _metric_value)
DEFAULT:
|
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Preprocessor
¶
Bases: DoFn
Preprocessor wrapper for preprocessing data in the metric computation.
The preprocessor is a beam.DoFn that takes a extracts (or a list of extracts) as input (which typically will contain labels, predictions, example weights, and optionally features) and should return the initial state that the combiner will use as input. The output of a processor should only contain information needed by the combiner. Note that if a query_key is used the preprocessor will be passed a list of extracts as input representing the extracts that matched the query_key. The special FeaturePreprocessor can be used to add additional features to the default standard metric inputs.
ATTRIBUTE | DESCRIPTION |
---|---|
name |
The name of the preprocessor. It should only be accessed by a property function. It is a read only attribute, and is used to distinguish different preprocessors.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/metric_types.py
Prevalence
¶
Prevalence(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Prevalence.
Initializes prevalence.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
PrevalenceThreshold
¶
PrevalenceThreshold(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Prevalence threshold (PT).
Initializes prevalence threshold.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
Function for computing metric value from TP, TN, FP, FN values.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
QueryStatistics
¶
QueryStatistics(
total_queries_name: str = TOTAL_QUERIES_NAME,
total_documents_name: str = TOTAL_DOCUMENTS_NAME,
min_documents_name: str = MIN_DOCUMENTS_NAME,
max_documents_name: str = MAX_DOCUMENTS_NAME,
)
Bases: Metric
Query statistic metrics.
These metrics are query/ranking based so a query_key must also be provided in the associated metrics spec.
Initializes query statistics metrics.
PARAMETER | DESCRIPTION |
---|---|
total_queries_name
|
Total queries metric name.
TYPE:
|
total_documents_name
|
Total documents metric name.
TYPE:
|
min_documents_name
|
Min documents name.
TYPE:
|
max_documents_name
|
Max documents name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/query_statistics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
Recall
¶
Recall(
thresholds: Optional[Union[float, List[float]]] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
name: Optional[str] = None,
**kwargs,
)
Bases: ConfusionMatrixMetric
Computes the recall of the predictions with respect to the labels.
The metric uses true positives and false negatives to compute recall by dividing the true positives by the sum of true positives and false negatives.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes Recall metric.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) A float value or a python list/tuple of float
threshold values in [0, 1]. A threshold is compared with prediction
values to determine the truth value of predictions (i.e., above the
threshold is |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
name
|
(Optional) string name of the metric instance. |
**kwargs
|
(Optional) Additional args to pass along to init (and eventually on to _metric_computation and _metric_value)
DEFAULT:
|
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
RecallAtPrecision
¶
RecallAtPrecision(
precision: float,
num_thresholds: Optional[int] = None,
class_id: Optional[int] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
)
Bases: ConfusionMatrixMetricBase
Computes best recall where precision is >= specified value.
For a given score-label-distribution the required precision might not be achievable, in this case 0.0 is returned as recall.
This metric creates three local variables, true_positives
, false_positives
and false_negatives
that are used to compute the recall at the given
precision. The threshold for the given precision value is computed and used to
evaluate the corresponding recall.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes RecallAtPrecision.
PARAMETER | DESCRIPTION |
---|---|
precision
|
A scalar value in range
TYPE:
|
num_thresholds
|
(Optional) Defaults to 1000. The number of thresholds to use for matching the given precision. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
name
|
(Optional) string name of the metric instance. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
RelativeCoefficientOfDiscrimination
¶
RelativeCoefficientOfDiscrimination(
name: str = RELATIVE_COEFFICIENT_OF_DISCRIMINATION_NAME,
)
Bases: Metric
Relative coefficient of discrimination metric.
The relative coefficient of discrimination measures the ratio between the average prediction for the positive examples and the average prediction for the negative examples. This has a very simple intuitive explanation, measuring how much higher is the prediction going to be for a positive example than for a negative example.
Initializes relative coefficient of discrimination metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/tjur_discrimination.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
ScoreDistributionPlot
¶
ScoreDistributionPlot(
num_thresholds: int = DEFAULT_NUM_THRESHOLDS,
name: str = SCORE_DISTRIBUTION_PLOT_NAME,
)
Bases: Metric
Score distribution plot.
Initializes confusion matrix plot.
PARAMETER | DESCRIPTION |
---|---|
num_thresholds
|
Number of thresholds to use when discretizing the curve. Values must be > 1. Defaults to 1000.
TYPE:
|
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/score_distribution_plot.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
SemanticSegmentationConfusionMatrix
¶
SemanticSegmentationConfusionMatrix(
class_ids: List[int],
ground_truth_key: str,
prediction_key: str,
decode_ground_truth: bool = True,
decode_prediction: bool = False,
ignore_ground_truth_id: Optional[int] = None,
name: Optional[str] = None,
)
Bases: Metric
Computes confusion matrices for semantic segmentation.
Initializes PrecisionAtRecall metric.
PARAMETER | DESCRIPTION |
---|---|
class_ids
|
the class ids for calculating metrics. |
ground_truth_key
|
the key for storing the ground truth of encoded image with class ids.
TYPE:
|
prediction_key
|
the key for storing the predictions of encoded image with class ids.
TYPE:
|
decode_ground_truth
|
If true, the ground truth is assumed to be bytes of images and will be decoded. By default it is true assuming the label is the bytes of image.
TYPE:
|
decode_prediction
|
If true, the prediction is assumed to be bytes of images and will be decoded. By default it is false assuming the model outputs numpy arrays or tensors.
TYPE:
|
ignore_ground_truth_id
|
(Optional) The id of ground truth to be ignored. |
name
|
(Optional) string name of the metric instance. |
Source code in tensorflow_model_analysis/metrics/semantic_segmentation_confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
SemanticSegmentationFalsePositive
¶
SemanticSegmentationFalsePositive(
class_ids: List[int],
ground_truth_key: str,
prediction_key: str,
decode_ground_truth: bool = True,
decode_prediction: bool = False,
ignore_ground_truth_id: Optional[int] = None,
name: Optional[str] = None,
)
Bases: SemanticSegmentationConfusionMatrixMetricBase
Calculates the true postive for semantic segmentation.
Initializes PrecisionAtRecall metric.
PARAMETER | DESCRIPTION |
---|---|
class_ids
|
the class ids for calculating metrics. |
ground_truth_key
|
the key for storing the ground truth of encoded image with class ids.
TYPE:
|
prediction_key
|
the key for storing the predictions of encoded image with class ids.
TYPE:
|
decode_ground_truth
|
If true, the ground truth is assumed to be bytes of images and will be decoded. By default it is true assuming the label is the bytes of image.
TYPE:
|
decode_prediction
|
If true, the prediction is assumed to be bytes of images and will be decoded. By default it is false assuming the model outputs numpy arrays or tensors.
TYPE:
|
ignore_ground_truth_id
|
(Optional) The id of ground truth to be ignored. |
name
|
(Optional) string name of the metric instance. |
Source code in tensorflow_model_analysis/metrics/semantic_segmentation_confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
SemanticSegmentationTruePositive
¶
SemanticSegmentationTruePositive(
class_ids: List[int],
ground_truth_key: str,
prediction_key: str,
decode_ground_truth: bool = True,
decode_prediction: bool = False,
ignore_ground_truth_id: Optional[int] = None,
name: Optional[str] = None,
)
Bases: SemanticSegmentationConfusionMatrixMetricBase
Calculates the true postive for semantic segmentation.
Initializes PrecisionAtRecall metric.
PARAMETER | DESCRIPTION |
---|---|
class_ids
|
the class ids for calculating metrics. |
ground_truth_key
|
the key for storing the ground truth of encoded image with class ids.
TYPE:
|
prediction_key
|
the key for storing the predictions of encoded image with class ids.
TYPE:
|
decode_ground_truth
|
If true, the ground truth is assumed to be bytes of images and will be decoded. By default it is true assuming the label is the bytes of image.
TYPE:
|
decode_prediction
|
If true, the prediction is assumed to be bytes of images and will be decoded. By default it is false assuming the model outputs numpy arrays or tensors.
TYPE:
|
ignore_ground_truth_id
|
(Optional) The id of ground truth to be ignored. |
name
|
(Optional) string name of the metric instance. |
Source code in tensorflow_model_analysis/metrics/semantic_segmentation_confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
SensitivityAtSpecificity
¶
SensitivityAtSpecificity(
specificity: Union[float, List[float]],
num_thresholds: Optional[int] = None,
class_id: Optional[int] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
)
Bases: ConfusionMatrixMetricBase
Computes best sensitivity where specificity is >= specified value.
Sensitivity
measures the proportion of actual positives that are correctly
identified as such (tp / (tp + fn)).
Specificity
measures the proportion of actual negatives that are correctly
identified as such (tn / (tn + fp)).
The threshold for the given specificity value is computed and used to evaluate the corresponding sensitivity.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
For additional information about specificity and sensitivity, see the following.
Initializes SensitivityAtSpecificity metric.
PARAMETER | DESCRIPTION |
---|---|
specificity
|
A scalar value in range |
num_thresholds
|
(Optional) Defaults to 1000. The number of thresholds to use for matching the given specificity. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
name
|
(Optional) string name of the metric instance. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
SetMatchPrecision
¶
SetMatchPrecision(
thresholds: Optional[Union[float, List[float]]] = None,
top_k: Optional[int] = None,
name: Optional[str] = None,
prediction_class_key: str = "classes",
prediction_score_key: str = "scores",
class_key: Optional[str] = None,
weight_key: Optional[str] = None,
**kwargs,
)
Bases: Precision
Computes precision for sets of labels and predictions.
The metric deals with labels and predictions which are provided in the format of sets (stored as variable length numpy arrays). The precision is the micro averaged classification precision. The metric is suitable for the case where the number of classes is large or the list of classes could not be provided in advance.
Example: Label: ['cats'], Predictions: {'classes': ['cats, dogs']}
The precision is 0.5.
Initializes Precision metric.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) A float value or a python list/tuple of float
threshold values in [0, 1]. A threshold is compared with prediction
values to determine the truth value of predictions (i.e., above the
threshold is |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are truncated and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. When top_k is used, the default threshold is float('-inf'). In this case, unmatched labels are still considered false negative, since they have prediction with confidence score float('-inf'), |
name
|
(Optional) string name of the metric instance. |
prediction_class_key
|
the key name of the classes in prediction.
TYPE:
|
prediction_score_key
|
the key name of the scores in prediction.
TYPE:
|
class_key
|
(Optional) The key name of the classes in class-weight pairs. If it is not provided, the classes are assumed to be the label classes. |
weight_key
|
(Optional) The key name of the weights of classes in class-weight pairs. The value in this key should be a numpy array of the same length as the classes in class_key. The key should be stored under the features key. |
**kwargs
|
(Optional) Additional args to pass along to init (and eventually on to _metric_computations and _metric_values). The args are passed to the precision metric, the confusion matrix metric and binary classification metric.
DEFAULT:
|
Source code in tensorflow_model_analysis/metrics/set_match_confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
SetMatchRecall
¶
SetMatchRecall(
thresholds: Optional[Union[float, List[float]]] = None,
top_k: Optional[int] = None,
name: Optional[str] = None,
prediction_class_key: str = "classes",
prediction_score_key: str = "scores",
class_key: Optional[str] = None,
weight_key: Optional[str] = None,
**kwargs,
)
Bases: Recall
Computes recall for sets of labels and predictions.
The metric deals with labels and predictions which are provided in the format of sets (stored as variable length numpy arrays). The recall is the micro averaged classification recall. The metric is suitable for the case where the number of classes is large or the list of classes could not be provided in advance.
Example: Label: ['cats'], Predictions: {'classes': ['cats, dogs']}
The recall is 1.
Initializes recall metric.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) A float value or a python list/tuple of float
threshold values in [0, 1]. A threshold is compared with prediction
values to determine the truth value of predictions (i.e., above the
threshold is |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are truncated and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. When top_k is used, the default threshold is float('-inf'). In this case, unmatched labels are still considered false negative, since they have prediction with confidence score float('-inf'), |
name
|
(Optional) string name of the metric instance. |
prediction_class_key
|
the key name of the classes in prediction.
TYPE:
|
prediction_score_key
|
the key name of the scores in prediction.
TYPE:
|
class_key
|
(Optional) The key name of the classes in class-weight pairs. If it is not provided, the classes are assumed to be the label classes. |
weight_key
|
(Optional) The key name of the weights of classes in class-weight pairs. The value in this key should be a numpy array of the same length as the classes in class_key. The key should be stored under the features key. |
**kwargs
|
(Optional) Additional args to pass along to init (and eventually on to _metric_computations and _metric_values). The args are passed to the recall metric, the confusion matrix metric and binary classification metric.
DEFAULT:
|
Source code in tensorflow_model_analysis/metrics/set_match_confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
Specificity
¶
Specificity(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Specificity (TNR) or selectivity.
Initializes specificity metric.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use for specificity. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
SpecificityAtSensitivity
¶
SpecificityAtSensitivity(
sensitivity: float,
num_thresholds: Optional[int] = None,
class_id: Optional[int] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
)
Bases: ConfusionMatrixMetricBase
Computes best specificity where sensitivity is >= specified value.
Sensitivity
measures the proportion of actual positives that are correctly
identified as such (tp / (tp + fn)).
Specificity
measures the proportion of actual negatives that are correctly
identified as such (tn / (tn + fp)).
The threshold for the given sensitivity value is computed and used to evaluate the corresponding specificity.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
For additional information about specificity and sensitivity, see the following.
Initializes SpecificityAtSensitivity metric.
PARAMETER | DESCRIPTION |
---|---|
sensitivity
|
A scalar value or a list of scalar value in range
TYPE:
|
num_thresholds
|
(Optional) Defaults to 1000. The number of thresholds to use for matching the given sensitivity. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
name
|
(Optional) string name of the metric instance. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
SquaredPearsonCorrelation
¶
SquaredPearsonCorrelation(
name: str = SQUARED_PEARSON_CORRELATION_NAME,
)
Bases: Metric
Squared pearson correlation (r^2) metric.
Initializes squared pearson correlation (r^2) metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/squared_pearson_correlation.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
StandardMetricInputs
¶
Bases: StandardExtracts
Standard inputs used by most metric computations.
StandardMetricInputs is a wrapper around Extracts where only the extracts keys used by one or more ExtractsPreprocessors will be present.
Initializes StandardExtracts.
PARAMETER | DESCRIPTION |
---|---|
extracts
|
Reference to existing extracts to use. |
**kwargs
|
Name/value pairs to create new extracts from. Only one of either extracts or kwargs should be used.
DEFAULT:
|
Source code in tensorflow_model_analysis/utils/util.py
Attributes¶
example_weight
property
¶
example_weight: Optional[TensorValueMaybeMultiLevelDict]
Same as example_weights (DEPRECATED - use example_weights).
label
property
¶
Same as labels (DEPRECATED - use labels).
prediction
property
¶
prediction: Optional[TensorValueMaybeMultiLevelDict]
Same as predictions (DEPRECATED - use predictions).
Functions¶
get_attributions
¶
get_attributions(
model_name: Optional[str] = None,
output_name: Optional[str] = None,
) -> Optional[DictOfTensorValueMaybeDict]
Returns tfma.ATTRIBUTIONS_KEY extract.
Source code in tensorflow_model_analysis/utils/util.py
get_by_key
¶
Returns item for key possibly filtered by model and/or output names.
Source code in tensorflow_model_analysis/metrics/metric_types.py
get_combined_features
¶
Returns a combined extract of transformed features and features.
In case of name collision, transformed features is looked up first and the value is returned when found.
PARAMETER | DESCRIPTION |
---|---|
model_name
|
Optionally, the model name assosicated to the transformed feature. This has no effect on the raw features extract. |
Source code in tensorflow_model_analysis/utils/util.py
get_example_weights
¶
get_example_weights(
model_name: Optional[str] = None,
output_name: Optional[str] = None,
) -> Optional[TensorValueMaybeMultiLevelDict]
Returns tfma.EXAMPLE_WEIGHTS_KEY extract.
Source code in tensorflow_model_analysis/utils/util.py
get_features
¶
get_features() -> Optional[DictOfTensorValueMaybeDict]
get_labels
¶
get_labels(
model_name: Optional[str] = None,
output_name: Optional[str] = None,
) -> Optional[TensorValueMaybeMultiLevelDict]
Returns tfma.LABELS_KEY extract.
Source code in tensorflow_model_analysis/utils/util.py
get_model_and_output_names
¶
Returns a list of model_name-output_name tuples present in extracts.
Source code in tensorflow_model_analysis/utils/util.py
get_predictions
¶
get_predictions(
model_name: Optional[str] = None,
output_name: Optional[str] = None,
) -> Optional[TensorValueMaybeMultiLevelDict]
Returns tfma.PREDICTIONS_KEY extract.
Source code in tensorflow_model_analysis/utils/util.py
get_transformed_features
¶
get_transformed_features(
model_name: Optional[str] = None,
) -> Optional[DictOfTensorValueMaybeDict]
Returns tfma.TRANSFORMED_FEATURES_KEY extract.
Source code in tensorflow_model_analysis/utils/util.py
set_labels
¶
set_labels(
labels: TensorValueMaybeMultiLevelDict,
model_name: Optional[str] = None,
output_name: Optional[str] = None,
) -> Optional[TensorValueMaybeMultiLevelDict]
Sets tfma.LABELS_KEY extract for a given model and output.
Source code in tensorflow_model_analysis/utils/util.py
set_predictions
¶
set_predictions(
predictions: TensorValueMaybeMultiLevelDict,
model_name: Optional[str] = None,
output_name: Optional[str] = None,
) -> Optional[TensorValueMaybeMultiLevelDict]
Sets tfma.PREDICTIONS_KEY extract for a given model and output.
Source code in tensorflow_model_analysis/utils/util.py
SubKey
¶
Bases: NamedTuple('SubKey', [('class_id', int), ('k', int), ('top_k', int)])
A SubKey identifies a sub-types of metrics and plots.
Only one of class_id, k, or top_k can be set at a time.
ATTRIBUTE | DESCRIPTION |
---|---|
class_id |
Used with multi-class metrics to identify a specific class ID.
|
k |
Used with multi-class metrics to identify the kth predicted value.
|
top_k |
Used with multi-class and ranking metrics to identify top-k predicted values.
|
Functions¶
from_proto
staticmethod
¶
Creates class from proto.
Source code in tensorflow_model_analysis/metrics/metric_types.py
to_proto
¶
Converts key to proto.
Source code in tensorflow_model_analysis/metrics/metric_types.py
SymmetricPredictionDifference
¶
SymmetricPredictionDifference(
name: str = SYMMETRIC_PREDICITON_DIFFERENCE_NAME,
)
Bases: Metric
PredictionDifference computes the avg pointwise diff between models.
Initializes PredictionDifference metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/prediction_difference_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
TN
¶
TN(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: TrueNegatives
Alias for TrueNegatives.
Initializes TN metric.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
TNR
¶
TNR(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: Specificity
Alias for Specificity.
Initializes TNR metric.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
TP
¶
TP(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: TruePositives
Alias for TruePositives.
Initializes TP metric.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
TPR
¶
TPR(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: Recall
Alias for Recall.
Initializes TPR metric.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
ThreatScore
¶
ThreatScore(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Threat score or critical success index (TS or CSI).
Initializes threat score.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Thresholds to use. Defaults to [0.5]. |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
result
¶
TotalAbsoluteAttributions
¶
TotalAbsoluteAttributions(
name: str = TOTAL_ABSOLUTE_ATTRIBUTIONS_NAME,
)
Bases: AttributionsMetric
Total absolute attributions metric.
Initializes total absolute attributions metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
Attribution metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/attributions.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
TotalAttributions
¶
TotalAttributions(name: str = TOTAL_ATTRIBUTIONS_NAME)
Bases: AttributionsMetric
Total attributions metric.
Initializes total attributions metric.
PARAMETER | DESCRIPTION |
---|---|
name
|
Attribution metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/attributions.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
TrueNegatives
¶
TrueNegatives(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Calculates the number of true negatives.
If sample_weight
is given, calculates the sum of the weights of true
negatives.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes TrueNegatives metric.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Defaults to [0.5]. A float value or a python
list/tuple of float threshold values in [0, 1]. A threshold is compared
with prediction values to determine the truth value of predictions
(i.e., above the threshold is |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
TruePositives
¶
TruePositives(
thresholds: Optional[Union[float, List[float]]] = None,
name: Optional[str] = None,
top_k: Optional[int] = None,
class_id: Optional[int] = None,
)
Bases: ConfusionMatrixMetric
Calculates the number of true positives.
If sample_weight
is given, calculates the sum of the weights of
true positives. This metric creates one local variable, true_positives
that is used to keep track of the number of true positives.
If sample_weight
is None
, weights default to 1.
Use sample_weight
of 0 to mask values.
Initializes TruePositives metric.
PARAMETER | DESCRIPTION |
---|---|
thresholds
|
(Optional) Defaults to [0.5]. A float value or a python
list/tuple of float threshold values in [0, 1]. A threshold is compared
with prediction values to determine the truth value of predictions
(i.e., above the threshold is |
name
|
(Optional) Metric name. |
top_k
|
(Optional) Used with a multi-class model to specify that the top-k values should be used to compute the confusion matrix. The net effect is that the non-top-k values are set to -inf and the matrix is then constructed from the average TP, FP, TN, FN across the classes. When top_k is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. When top_k is set, the default thresholds are [float('-inf')]. |
class_id
|
(Optional) Used with a multi-class model to specify which class to compute the confusion matrix for. When class_id is used, metrics_specs.binarize settings must not be present. Only one of class_id or top_k should be configured. |
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Whether to compute confidence intervals for this metric.
Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals for this metric. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
get_config
¶
Returns serializable config.
Source code in tensorflow_model_analysis/metrics/confusion_matrix_metrics.py
WeightedExampleCount
¶
WeightedExampleCount(
name: str = WEIGHTED_EXAMPLE_COUNT_NAME,
)
Bases: ExampleCount
Weighted example count (deprecated - use ExampleCount).
Initializes weighted example count.
PARAMETER | DESCRIPTION |
---|---|
name
|
Metric name.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/weighted_example_count.py
Attributes¶
compute_confidence_interval
property
¶
compute_confidence_interval: bool
Always disable confidence intervals for ExampleCount.
Confidence intervals capture uncertainty in a metric if it were computed on more examples. For ExampleCount, this sort of uncertainty is not meaningful, so confidence intervals are disabled.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether to compute confidence intervals. |
Functions¶
computations
¶
computations(
eval_config: Optional[EvalConfig] = None,
schema: Optional[Schema] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
sub_keys: Optional[List[Optional[SubKey]]] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
query_key: Optional[str] = None,
) -> MetricComputations
Creates computations associated with metric.
Source code in tensorflow_model_analysis/metrics/metric_types.py
from_config
classmethod
¶
Functions¶
CombinedFeaturePreprocessor
¶
CombinedFeaturePreprocessor(
feature_keys: Iterable[str],
include_default_inputs: bool = True,
model_names: Optional[Iterable[str]] = None,
output_names: Optional[Iterable[str]] = None,
) -> StandardMetricInputsPreprocessor
Returns preprocessor for incl combined features in StandardMetricInputs.
PARAMETER | DESCRIPTION |
---|---|
feature_keys
|
List of feature keys. An empty list means all. |
include_default_inputs
|
True to include default inputs (labels, predictions, example weights) in addition to the transformed features.
TYPE:
|
model_names
|
Optional model names (required if transformed_features used with multi-model evaluations). |
output_names
|
Optional output names. Only used if include_default_inputs is True. If unset all outputs will be included with the default inputs. |
Source code in tensorflow_model_analysis/metrics/metric_types.py
FeaturePreprocessor
¶
FeaturePreprocessor(
feature_keys: Iterable[str],
include_default_inputs: bool = True,
model_names: Optional[Iterable[str]] = None,
output_names: Optional[Iterable[str]] = None,
) -> StandardMetricInputsPreprocessor
Returns preprocessor for including features in StandardMetricInputs.
PARAMETER | DESCRIPTION |
---|---|
feature_keys
|
List of feature keys. An empty list means all. |
include_default_inputs
|
True to include default inputs (labels, predictions, example weights) in addition to the features.
TYPE:
|
model_names
|
Optional model names. Only used if include_default_inputs is True. If unset all models will be included with the default inputs. |
output_names
|
Optional output names. Only used if include_default_inputs is True. If unset all outputs will be included with the default inputs. |
Source code in tensorflow_model_analysis/metrics/metric_types.py
default_binary_classification_specs
¶
default_binary_classification_specs(
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
output_weights: Optional[Dict[str, float]] = None,
binarize: Optional[BinarizationOptions] = None,
aggregate: Optional[AggregationOptions] = None,
include_loss: bool = True,
) -> List[MetricsSpec]
Returns default metric specs for binary classification problems.
PARAMETER | DESCRIPTION |
---|---|
model_names
|
Optional model names (if multi-model evaluation). |
output_names
|
Optional list of output names (if multi-output model). |
output_weights
|
Optional output weights for creating overall metric aggregated across outputs (if multi-output model). If a weight is not provided for an output, it's weight defaults to 0.0 (i.e. output ignored). |
binarize
|
Optional settings for binarizing multi-class/multi-label metrics.
TYPE:
|
aggregate
|
Optional settings for aggregating multi-class/multi-label metrics.
TYPE:
|
include_loss
|
True to include loss.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/metric_specs.py
default_multi_class_classification_specs
¶
default_multi_class_classification_specs(
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
output_weights: Optional[Dict[str, float]] = None,
binarize: Optional[BinarizationOptions] = None,
aggregate: Optional[AggregationOptions] = None,
sparse: bool = True,
) -> List[MetricsSpec]
Returns default metric specs for multi-class classification problems.
PARAMETER | DESCRIPTION |
---|---|
model_names
|
Optional model names if multi-model evaluation. |
output_names
|
Optional list of output names (if multi-output model). |
output_weights
|
Optional output weights for creating overall metric aggregated across outputs (if multi-output model). If a weight is not provided for an output, it's weight defaults to 0.0 (i.e. output ignored). |
binarize
|
Optional settings for binarizing multi-class/multi-label metrics.
TYPE:
|
aggregate
|
Optional settings for aggregating multi-class/multi-label metrics.
TYPE:
|
sparse
|
True if the labels are sparse.
TYPE:
|
Source code in tensorflow_model_analysis/metrics/metric_specs.py
default_regression_specs
¶
default_regression_specs(
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
output_weights: Optional[Dict[str, float]] = None,
loss_functions: Optional[
List[Union[Metric, Loss]]
] = None,
min_value: Optional[float] = None,
max_value: Optional[float] = None,
) -> List[MetricsSpec]
Returns default metric specs for for regression problems.
PARAMETER | DESCRIPTION |
---|---|
model_names
|
Optional model names (if multi-model evaluation). |
output_names
|
Optional list of output names (if multi-output model). |
output_weights
|
Optional output weights for creating overall metric aggregated across outputs (if multi-output model). If a weight is not provided for an output, it's weight defaults to 0.0 (i.e. output ignored). |
loss_functions
|
Loss functions to use (if None MSE is used). |
min_value
|
Min value for calibration plot (if None no plot will be created). |
max_value
|
Max value for calibration plot (if None no plot will be created). |
Source code in tensorflow_model_analysis/metrics/metric_specs.py
has_attributions_metrics
¶
Returns true if any of the metrics_specs have attributions metrics.
Source code in tensorflow_model_analysis/metrics/attributions.py
merge_per_key_computations
¶
merge_per_key_computations(
create_computations_fn: Callable[
..., MetricComputations
],
) -> Callable[..., MetricComputations]
Wraps create_computations_fn to be called separately for each key.
Source code in tensorflow_model_analysis/metrics/metric_util.py
metric_thresholds_from_metrics_specs
¶
metric_thresholds_from_metrics_specs(
metrics_specs: Iterable[MetricsSpec],
eval_config: Optional[EvalConfig] = None,
) -> Dict[MetricKey, Iterable[_SliceAndThreshold]]
Returns thresholds associated with given metrics specs.
Source code in tensorflow_model_analysis/metrics/metric_specs.py
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
|
specs_from_metrics
¶
specs_from_metrics(
metrics: Optional[_MetricsOrLosses] = None,
unweighted_metrics: Optional[_MetricsOrLosses] = None,
model_names: Optional[List[str]] = None,
output_names: Optional[List[str]] = None,
output_weights: Optional[Dict[str, float]] = None,
binarize: Optional[BinarizationOptions] = None,
aggregate: Optional[AggregationOptions] = None,
query_key: Optional[str] = None,
include_example_count: Optional[bool] = None,
include_weighted_example_count: Optional[bool] = None,
) -> List[MetricsSpec]
Returns specs for tf_keras.metrics/losses or tfma.metrics classes.
Examples:
metrics_specs = specs_from_metrics( [ tf_keras.metrics.BinaryAccuracy(), tfma.metrics.AUC(), tfma.metrics.MeanLabel(), tfma.metrics.MeanPrediction() ... ], unweighted=[ tfma.metrics.Precision(), tfma.metrics.Recall() ])
metrics_specs = specs_from_metrics({ 'output1': [ tf_keras.metrics.BinaryAccuracy(), tfma.metrics.AUC(), tfma.metrics.MeanLabel(), tfma.metrics.MeanPrediction() ... ], 'output2': [ tfma.metrics.Precision(), tfma.metrics.Recall(), ] })
PARAMETER | DESCRIPTION |
---|---|
metrics
|
List of tfma.metrics.Metric, tf_keras.metrics.Metric, or tf_keras.losses.Loss. For multi-output models a dict of dicts may be passed where the first dict is indexed by the output_name. Whether these metrics are weighted or not will be determined based on whether the ModelSpec associated with the metrics contains example weight key settings or not.
TYPE:
|
unweighted_metrics
|
Same as metrics only these metrics will not be weighted by example_weight regardless of the example weight key settings.
TYPE:
|
model_names
|
Optional model names (if multi-model evaluation). |
output_names
|
Optional output names (if multi-output models). If the metrics are a dict this should not be set. |
output_weights
|
Optional output weights for creating overall metric aggregated across outputs (if multi-output model). If a weight is not provided for an output, it's weight defaults to 0.0 (i.e. output ignored). |
binarize
|
Optional settings for binarizing multi-class/multi-label metrics.
TYPE:
|
aggregate
|
Optional settings for aggregating multi-class/multi-label metrics.
TYPE:
|
query_key
|
Optional query key for query/ranking based metrics. |
include_example_count
|
True to add example_count metric. Default is True. |
include_weighted_example_count
|
True to add weighted example_count metric. Default is True. A weighted example count will be added per output for multi-output models. |
RETURNS | DESCRIPTION |
---|---|
List[MetricsSpec]
|
MetricsSpecs based on options provided. A separate spec is returned for |
List[MetricsSpec]
|
weighted vs unweighted metrics. A separate spec is also returned for each |
List[MetricsSpec]
|
output if a dict of metrics per output is passed. |
Source code in tensorflow_model_analysis/metrics/metric_specs.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
to_label_prediction_example_weight
¶
to_label_prediction_example_weight(
inputs: StandardMetricInputs,
eval_config: Optional[EvalConfig] = None,
model_name: str = "",
output_name: str = "",
sub_key: Optional[SubKey] = None,
aggregation_type: Optional[AggregationType] = None,
class_weights: Optional[Dict[int, float]] = None,
example_weighted: bool = False,
fractional_labels: bool = False,
flatten: bool = True,
squeeze: bool = True,
allow_none: bool = False,
require_single_example_weight: bool = False,
) -> Iterator[Tuple[ndarray, ndarray, ndarray]]
Yields label, prediction, and example weights for use in calculations.
Where applicable this function will perform model and output name lookups as well as any required class ID, top K, etc conversions. It will also apply prediction keys and label vocabularies given the necessary information is provided as part of the EvalConfig (or standard estimator based naming is used). The sparseness of labels will be inferred from the shapes of the labels and predictions (i.e. if the shapes are different then the labels will be assumed to be sparse).
If successful, the final output of calling this function will be a tuple of numpy arrays representing the label, prediction, and example weight respectively. Labels and predictions will be returned in the same shape provided (default behavior) unless (1) flatten is True in which case a series of values (one per class ID) will be returned with last dimension of size 1 or (2) a sub_key is used in which case the last dimension may be re-shaped to match the new number of outputs (1 for class_id or k, top_k for top k with aggregation).
Note that for top_k without aggregation, the non-top_k prediction values will be set to float('-inf'), but for top_k with aggregation the values will be truncated to only return the top k values.
Examples:
# default behavior # # Binary classification Input : labels=[1] predictions=[0.6] Output : (np.array([1]), np.array([0.6]), np.array([1.0])) # Multi-class classification w/ sparse labels Input : labels=[2] predictions=[0.3, 0.6, 0.1] Output: (np.array([2]), np.array([0.3, 0.6, 0.1]), np.array([1.0])) # Multi-class / multi-label classification w/ dense labels Input : labels=[0, 1, 1] predictions=[0.3, 0.6, 0.1] Output : (np.array([0, 1, 1]), np.array([0.3, 0.6, 0.1]), np.array([1.0]))
# flatten=True # # Multi-class classification w/ sparse labels Input : labels=[2], predictions=[0.3, 0.6, 0.1] Output : (np.array([0]), np.array([0.3]), np.array([1.0])), (np.array([0]), np.array([0.6]), np.array([1.0])), (np.array([1]), np.array([0.1]), np.array([1.0])) # Multi-class/multi-label classification w/ dense labels Input : labels=[0, 0, 1], predictions=[0.3, 0.6, 0.1] Output : (np.array([0]), np.array([0.3]), np.array([1.0])), (np.array([0]), np.array([0.6]), np.array([1.0])), (np.array([1]), np.array([0.1]), np.array([1.0]))
# sub_key.class_id=[2] # # Multi-class classification w/ sparse labels Input : labels=[2] predictions=[0.3, 0.6, 0.1] Output : (np.array([1]), np.array([0.1]), np.array([1.0])) # Multi-class classification w/ dense labels Input : labels=[0, 0, 1] predictions=[0.3, 0.6, 0.1] Output : (np.array([1]), np.array([0.1]), np.array([1.0]))
# sub_key.top_k=2 and aggregation_type is None (i.e. binarization of top 2). # # Multi-class classification w/ sparse labels Input : labels=[2] predictions=[0.3, 0.6, 0.1] Output : (np.array([0, 0, 1]), np.array([0.3, 0.6, -inf]), np.array([1.0])) # Multi-class classification w/ dense labels Input : labels=[0, 0, 1] predictions=[0.3, 0.1, 0.6] Output : (np.array([0, 0, 1]), np.array([0.3, -inf, 0.6]), np.array([1.0]))
# sub_key.top_k=2 and aggregation_type is not None (i.e. aggregate top 2). # # Multi-class classification w/ sparse labels Input : labels=[2] predictions=[0.3, 0.6, 0.1] Output : (np.array([0, 1]), np.array([0.3, 0.6]), np.array([1.0])) # Multi-class classification w/ dense labels Input : labels=[0, 0, 1] predictions=[0.3, 0.1, 0.6] Output : (np.array([0, 0]), np.array([0.3, 0.6]), np.array([1.0]))
# sub_key.k=2 (i.e. binarization by choosing 2nd largest predicted value). # # Multi-class classification w/ sparse labels Input : labels=[0] predictions=[0.3, 0.6, 0.1] Output : (np.array([1]), np.array([0.3]), np.array([1.0])) # Multi-class classification w/ dense labels Input : labels=[0] predictions=[0.3] Output : (np.array([0]), np.array([0.3]), np.array([1.0]))
PARAMETER | DESCRIPTION |
---|---|
inputs
|
Standard metric inputs.
TYPE:
|
eval_config
|
Eval config
TYPE:
|
model_name
|
Optional model name (if multi-model evaluation).
TYPE:
|
output_name
|
Optional output name (if multi-output model type).
TYPE:
|
sub_key
|
Optional sub key. |
aggregation_type
|
Optional aggregation type.
TYPE:
|
class_weights
|
Optional class weights to apply to multi-class / multi-label labels and predictions. If used, flatten must also be True. |
example_weighted
|
True if example weights should be applied.
TYPE:
|
fractional_labels
|
If true, each incoming tuple of (label, prediction, and example weight) will be split into two tuples as follows (where l, p, w represent the resulting label, prediction, and example weight values): (1) l = 0.0, p = prediction, and w = example_weight * (1.0 - label) (2) l = 1.0, p = prediction, and w = example_weight * label If enabled, an exception will be raised if labels are not within [0, 1]. The implementation is such that tuples associated with a weight of zero are not yielded. This means it is safe to enable fractional_labels even when the labels only take on the values of 0.0 or 1.0.
TYPE:
|
flatten
|
True to flatten the final label and prediction outputs so that the yielded values are always arrays of size 1. For example, multi-class / multi-label outputs would be converted into label and prediction pairs that could then be processed by a binary classification metric in order to compute a micro average over all classes. If the example weight is not a scalar, then they will be flattened as well, otherwise the same example weight value will be output for each pair of labels and predictions.
TYPE:
|
squeeze
|
True to squeeze any outputs that have rank > 1. This transforms outputs such as np.array([[1]]) to np.array([1]).
TYPE:
|
allow_none
|
True to allow labels or predictions with None values to be returned. When used, the values will be returned as empty np.ndarrays. The example weight will always be non-empty.
TYPE:
|
require_single_example_weight
|
True to require that the example_weight be a single value.
TYPE:
|
YIELDS | DESCRIPTION |
---|---|
Tuple[ndarray, ndarray, ndarray]
|
Tuple of (label, prediction, example_weight). |
Source code in tensorflow_model_analysis/metrics/metric_util.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 |
|
to_standard_metric_inputs
¶
to_standard_metric_inputs(
extracts: Extracts,
include_labels: bool = True,
include_predictions: bool = True,
include_features: bool = False,
include_transformed_features: bool = False,
include_any_feature: bool = False,
include_attributions: bool = False,
) -> StandardMetricInputs
Verifies extract keys and converts extracts to StandardMetricInputs.