tfma.analyze_raw_data
Stay organized with collections Save and categorize content based on your preferences.
Runs TensorFlow model analysis on a pandas.DataFrame.
tfma.analyze_raw_data(
data: pd.DataFrame,
eval_config: Optional[tfma.EvalConfig
] = None,
output_path: Optional[str] = None,
extractors: Optional[List[extractor.Extractor]] = None,
evaluators: Optional[List[evaluator.Evaluator]] = None,
writers: Optional[List[writer.Writer]] = None,
add_metric_callbacks: Optional[List[types.AddMetricsCallbackType]] = None
) -> tfma.EvalResult
Used in the notebooks
This function allows you to use TFMA with Pandas DataFrames. The dataframe must include a 'predicted' column for the predicted label and a 'label' column for the actual label.
In addition to a DataFrame, this function requires an eval_config, a tfma.EvalConfig
object containing various configuration parameters (see config.proto for a comprehensive list)...
- the metrics to compute
- the slices to compute metrics on
- the DataFrame's column names for example labels and predictions ('label' and 'prediction' by default)
- confidence interval options
This function returns a tfma.EvalResult
, which contains TFMA's computed metrics and can be used to generate plots with tfma.view.render_slicing_metrics
.
Example usage:
model_specs = [
tfma.ModelSpec(
prediction_key='prediction',
label_key='label')
]
metrics_specs = [
tfma.MetricsSpec(metrics=[
tfma.MetricConfig(class_name='Accuracy'),
tfma.MetricConfig(class_name='ExampleCount')
])
]
slicing_specs = [
tfma.SlicingSpec(), # the empty slice represents overall dataset
tfma.SlicingSpec(feature_keys=['language'])
]
eval_config = tfma.EvalConfig(
model_specs=model_specs,
metrics_specs=metrics_specs,
slicing_specs=slicing_specs)
result = tfma.analyze_raw_data(df, eval_config)
tfma.view.render_slicing_metrics(result)
# Example with Fairness Indicators
from tensorflow_model_analysis.addons.fairness.post_export_metrics import
fairness_indicators
from tensorflow_model_analysis.addons.fairness.view import widget_view
add_metrics_callbacks = [
tfma.post_export_metrics.fairness_indicators(thresholds=[0.25, 0.5, 0.75])
]
result = tfma.analyze_raw_data(
data=df,
metrics_specs=metrics_specs,
slicing_specs=slicing_specs,
add_metric_callbacks=add_metrics_callbacks
)
widget_view.render_fairness_indicator(result)
Args |
---|
data | A pandas.DataFrame, where rows correspond to examples and columns correspond to features. One column must indicate a row's predicted label, and one column must indicate a row's actual label. |
eval_config | A tfma.EvalConfig , which contains various configuration parameters including metrics, slices, and label/prediction column names. |
output_path | Path to write EvalResult to. |
extractors | Optional list of Extractors to apply to Extracts. Typically these will be added by calling the default_extractors function. If no extractors are provided, default_extractors (non-materialized) will be used. |
evaluators | Optional list of Evaluators for evaluating Extracts. Typically these will be added by calling the default_evaluators function. If no evaluators are provided, default_evaluators will be used. |
writers | Optional list of Writers for writing Evaluation output. Typically these will be added by calling the default_writers function. If no writers are provided, default_writers with add_metric_callbacks will be used. |
add_metric_callbacks | Optional list of metric callbacks (if used). |
Returns |
---|
A tfma.EvalResult to extract metrics or generate visualizations from. |
Raises |
---|
KeyError | If the prediction or label columns are not found within the DataFrame. |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[]]