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."],[],[],null,["# tfma.analyze_raw_data\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/model-analysis/blob/v0.46.0/tensorflow_model_analysis/api/model_eval_lib.py#L1452-L1588) |\n\nRuns TensorFlow model analysis on a pandas.DataFrame. \n\n tfma.analyze_raw_data(\n data: pd.DataFrame,\n eval_config: Optional[../tfma/EvalConfig] = None,\n output_path: Optional[str] = None,\n extractors: Optional[List[extractor.Extractor]] = None,\n evaluators: Optional[List[evaluator.Evaluator]] = None,\n writers: Optional[List[writer.Writer]] = None,\n add_metric_callbacks: Optional[List[types.AddMetricsCallbackType]] = None\n ) -\u003e ../tfma/EvalResult\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Pandas DataFrame to Fairness Indicators Case Study](https://www.tensorflow.org/responsible_ai/fairness_indicators/tutorials/Fairness_Indicators_Pandas_Case_Study) |\n\nThis function allows you to use TFMA with Pandas DataFrames. The dataframe\nmust include a 'predicted' column for the predicted label and a 'label' column\nfor the actual label.\n\nIn addition to a DataFrame, this function requires an eval_config, a\n[`tfma.EvalConfig`](../tfma/EvalConfig) object containing various configuration parameters (see\n[config.proto](https://github.com/tensorflow/model-analysis/blob/master/tensorflow_model_analysis/proto/config.proto)\nfor a comprehensive list)...\n\n- the metrics to compute\n- the slices to compute metrics on\n- the DataFrame's column names for example labels and predictions ('label' and 'prediction' by default)\n- confidence interval options\n\nThis function returns a [`tfma.EvalResult`](../tfma/EvalResult), which contains TFMA's computed\nmetrics and can be used to generate plots with\n[`tfma.view.render_slicing_metrics`](../tfma/view/render_slicing_metrics).\n\n#### Example usage:\n\n model_specs = [\n tfma.ModelSpec(\n prediction_key='prediction',\n label_key='label')\n ]\n metrics_specs = [\n tfma.MetricsSpec(metrics=[\n tfma.MetricConfig(class_name='Accuracy'),\n tfma.MetricConfig(class_name='ExampleCount')\n ])\n ]\n slicing_specs = [\n tfma.SlicingSpec(), # the empty slice represents overall dataset\n tfma.SlicingSpec(feature_keys=['language'])\n ]\n eval_config = tfma.EvalConfig(\n model_specs=model_specs,\n metrics_specs=metrics_specs,\n slicing_specs=slicing_specs)\n result = tfma.analyze_raw_data(df, eval_config)\n tfma.view.render_slicing_metrics(result)\n\n # Example with Fairness Indicators\n from tensorflow_model_analysis.addons.fairness.post_export_metrics import\n fairness_indicators\n from tensorflow_model_analysis.addons.fairness.view import widget_view\n add_metrics_callbacks = [\n tfma.post_export_metrics.fairness_indicators(thresholds=[0.25, 0.5, 0.75])\n ]\n result = tfma.analyze_raw_data(\n data=df,\n metrics_specs=metrics_specs,\n slicing_specs=slicing_specs,\n add_metric_callbacks=add_metrics_callbacks\n )\n widget_view.render_fairness_indicator(result)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `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. |\n| `eval_config` | A [`tfma.EvalConfig`](../tfma/EvalConfig), which contains various configuration parameters including metrics, slices, and label/prediction column names. |\n| `output_path` | Path to write EvalResult to. |\n| `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. |\n| `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. |\n| `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. |\n| `add_metric_callbacks` | Optional list of metric callbacks (if used). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A tfma.EvalResult to extract metrics or generate visualizations from. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|------------|------------------------------------------------------------------------|\n| `KeyError` | If the prediction or label columns are not found within the DataFrame. |\n\n\u003cbr /\u003e"]]