Complete the code to import the TensorFlow Model Analysis library.
import tensorflow_model_analysis as [1]
The standard alias for TensorFlow Model Analysis is tfma. This helps us use its functions easily.
Complete the code to create an evaluation config with accuracy metric.
eval_config = tfma.EvalConfig(metrics_specs=[tfma.MetricsSpec(metrics=[tfma.Metric('[1]')])])
The accuracy metric measures how often the model predicts correctly. It's commonly used for classification tasks.
Fix the error in the code to run the evaluation on the model and data.
eval_result = tfma.evaluate_model(model_location='[1]', data_location='gs://my_bucket/data')
The model location must be a full path accessible by TFMA, usually a Google Cloud Storage path starting with gs://.
Fill both blanks to define slicing specs for evaluation by 'age' and 'gender'.
eval_config = tfma.EvalConfig(slicing_specs=[tfma.SlicingSpec(feature_keys=[[1]]), tfma.SlicingSpec(feature_keys=[[2]])])
Slicing specs define how to split data for detailed evaluation. Here, we slice by 'age' and 'gender' features.
Fill all three blanks to extract accuracy from evaluation results for the first slice.
accuracy = eval_result.slicing_metrics[0].metrics['[1]'].double_value slice_key = eval_result.slicing_metrics[0].slice.[2] feature_value = slice_key['[3]']
We get the 'accuracy' metric value, then access the slice key for 'age', and finally get the 'gender' feature value from that slice.
