TFMA View¶
tensorflow_model_analysis.view
¶
Initializes TFMA's view rendering api.
Classes¶
SlicedMetrics
¶
Bases: NamedTuple('SlicedMetrics', [('slice', SliceKeyType), ('metrics', MetricsByOutputName)])
A tuple containing the metrics belonging to a slice.
The metrics are stored in a nested dictionary with the following levels:
- output_name: Optional output name associated with metric (for multi-output models). '' by default.
- sub_key: Optional sub key associated with metric (for multi-class models).
'' by default. See
tfma.metrics.SubKey
for more info. - metric_name: Name of the metric (
auc
,accuracy
, etc). - metric_value: A dictionary containing the metric's value. See
tfma.proto.metrics_for_slice_pb2.MetricValue
for more info.
Below is a sample SlicedMetrics:
(
(('color', 'green')),
{
'': { # default for single-output models
'': { # default sub_key for non-multiclass-classification models
'auc': {
'doubleValue': 0.7243943810462952
},
'accuracy': {
'doubleValue': 0.6488351225852966
}
}
}
}
)
Attributes¶
slice: A 2-element tuple representing a slice. The first element is the key of a feature (ex: 'color'), and the second element is the value (ex: 'green'). An empty tuple represents an 'overall' slice (i.e. one that encompasses the entire dataset. metrics: A nested dictionary containing metric names and values.
SlicedPlots
¶
Bases: NamedTuple('SlicedPlots', [('slice', SliceKeyType), ('plot', PlotsByOutputName)])
A tuple containing the plots belonging to a slice.
Attributes¶
slice: A 2-element tuple representing a slice. The first element is the key
of a feature (ex: 'color'), and the second element is the value (ex:
'green'). An empty tuple represents an 'overall' slice (i.e. one that
encompasses the entire dataset.
plot: A dict mapping output_name
and sub_key_id
to plot data. The data
contains histograms and confusion matrices, which can be rendered with the
tfma.view.render_plot
function.
Functions¶
render_plot
¶
render_plot(
result: EvalResult,
slicing_spec: Optional[
Union[SingleSliceSpec, SlicingSpec]
] = None,
output_name: Optional[str] = None,
class_id: Optional[int] = None,
top_k: Optional[int] = None,
k: Optional[int] = None,
label: Optional[str] = None,
) -> Optional[PlotViewer]
Renders the plot view as widget.
result: An tfma.EvalResult. slicing_spec: The tfma.SlicingSpec to identify the slice. Show overall if unset. output_name: A string representing the output name. class_id: A number representing the class id if multi class. top_k: The k used to compute prediction in the top k position. k: The k used to compute prediciton at the kth position. label: A partial label used to match a set of plots in the results.
A PlotViewer object if in Jupyter notebook; None if in Colab.
Source code in tensorflow_model_analysis/view/widget_view.py
render_slicing_attributions
¶
render_slicing_attributions(
result: EvalResult,
slicing_column: Optional[str] = None,
slicing_spec: Optional[
Union[SingleSliceSpec, SlicingSpec]
] = None,
metric_name: Optional[str] = None,
weighted_example_column: Optional[str] = None,
event_handlers: Optional[
Callable[[Dict[str, Union[str, float]]], None]
] = None,
) -> Optional[SlicingMetricsViewer]
Renders the slicing metrics view as widget.
result: An tfma.EvalResult. slicing_column: The column to slice on. slicing_spec: The tfma.SlicingSpec to filter results. If neither column nor spec is set, show overall. metric_name: Name of attributions metric to show attributions for. Optional if only one metric used. weighted_example_column: Override for the weighted example column. This can be used when different weights are applied in different aprts of the model (eg: multi-head). event_handlers: The event handlers
A SlicingMetricsViewer object if in Jupyter notebook; None if in Colab.
Source code in tensorflow_model_analysis/view/widget_view.py
render_slicing_metrics
¶
render_slicing_metrics(
result: EvalResult,
slicing_column: Optional[str] = None,
slicing_spec: Optional[
Union[SingleSliceSpec, SlicingSpec]
] = None,
weighted_example_column: Optional[str] = None,
event_handlers: Optional[
Callable[[Dict[str, Union[str, float]]], None]
] = None,
) -> Optional[SlicingMetricsViewer]
Renders the slicing metrics view as widget.
result: An tfma.EvalResult. slicing_column: The column to slice on. slicing_spec: The tfma.SlicingSpec to filter results. If neither column nor spec is set, show overall. weighted_example_column: Override for the weighted example column. This can be used when different weights are applied in different aprts of the model (eg: multi-head). event_handlers: The event handlers
A SlicingMetricsViewer object if in Jupyter notebook; None if in Colab.
Source code in tensorflow_model_analysis/view/widget_view.py
render_time_series
¶
render_time_series(
results: EvalResults,
slicing_spec: Optional[
Union[SingleSliceSpec, SlicingSpec]
] = None,
display_full_path: bool = False,
) -> Optional[TimeSeriesViewer]
Renders the time series view as widget.
results: An tfma.EvalResults. slicing_spec: A tfma.SlicingSpec determining the slice to show time series on. Show overall if not set. display_full_path: Whether to display the full path to model / data in the visualization or just show file name.
A TimeSeriesViewer object if in Jupyter notebook; None if in Colab.