# tfma.analyze_raw_data

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/model-analysis/blob/v0.46.0/tensorflow_model_analysis/api/model_eval_lib.py#L1452-L1588) |

Runs TensorFlow model analysis on a pandas.DataFrame.

    tfma.analyze_raw_data(
        data: pd.DataFrame,
        eval_config: Optional[https://www.tensorflow.org/tfx/model_analysis/api_docs/python/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
    ) -> https://www.tensorflow.org/tfx/model_analysis/api_docs/python/tfma/EvalResult

### Used in the notebooks

| Used in the tutorials |
|---|
| - [Pandas DataFrame to Fairness Indicators Case Study](https://www.tensorflow.org/responsible_ai/fairness_indicators/tutorials/Fairness_Indicators_Pandas_Case_Study) |

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`](https://www.tensorflow.org/tfx/model_analysis/api_docs/python/tfma/EvalConfig) object containing various configuration parameters (see
[config.proto](https://github.com/tensorflow/model-analysis/blob/master/tensorflow_model_analysis/proto/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`](https://www.tensorflow.org/tfx/model_analysis/api_docs/python/tfma/EvalResult), which contains TFMA's computed
metrics and can be used to generate plots with
[`tfma.view.render_slicing_metrics`](https://www.tensorflow.org/tfx/model_analysis/api_docs/python/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)

<br />

<br />

<br />

| ## 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`](https://www.tensorflow.org/tfx/model_analysis/api_docs/python/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). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A tfma.EvalResult to extract metrics or generate visualizations from. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `KeyError` | If the prediction or label columns are not found within the DataFrame. |

<br />