0
0
TensorFlowml~8 mins

Functional API basics in TensorFlow - Model Metrics & Evaluation

Choose your learning style9 modes available
Metrics & Evaluation - Functional API basics
Which metric matters for Functional API basics and WHY

When learning the Functional API, the key metric to watch is training loss and validation loss. These show how well the model is learning from data. Since the Functional API lets you build flexible models, watching loss helps you know if your model structure is working well.

Accuracy is also important for classification tasks to see if the model predicts correctly. But loss gives a clearer signal during training.

Confusion matrix example

For classification models built with the Functional API, a confusion matrix helps understand prediction errors:

      Actual \ Predicted | Positive | Negative
      -------------------|----------|---------
      Positive           |    50    |   10    
      Negative           |    5     |   35    
    

Here, True Positives (TP) = 50, False Negatives (FN) = 10, False Positives (FP) = 5, True Negatives (TN) = 35.

Precision vs Recall tradeoff with examples

Using the Functional API, you can build models for different tasks. Depending on the task, you choose metrics:

  • Precision: Important when false alarms are bad. Example: Email spam filter. You want to avoid marking good emails as spam.
  • Recall: Important when missing positive cases is bad. Example: Disease detection. You want to catch all sick patients.

Functional API lets you customize models to improve these metrics by changing layers or connections.

What "good" vs "bad" metric values look like

For a simple classification model built with the Functional API:

  • Good: Loss steadily decreases during training and validation. Accuracy above 80% on validation. Precision and recall balanced above 75%.
  • Bad: Loss stays high or increases. Accuracy stuck near random chance (e.g., 50% for two classes). Precision or recall very low (below 50%), showing poor predictions.
Common pitfalls in metrics when using Functional API
  • Accuracy paradox: High accuracy can be misleading if classes are imbalanced. For example, 95% accuracy if model always predicts the majority class.
  • Data leakage: Using test data during training can inflate metrics falsely.
  • Overfitting indicators: Training loss much lower than validation loss means model memorizes training data but fails on new data.
  • Ignoring metric choice: Not selecting metrics that fit the problem (e.g., using accuracy for imbalanced data) leads to wrong conclusions.
Self-check question

Your Functional API model shows 98% accuracy but only 12% recall on fraud detection. Is it good for production? Why or why not?

Answer: No, it is not good. The low recall means the model misses most fraud cases, which is dangerous. Even with high accuracy, the model fails to catch fraud, so it should be improved before use.

Key Result
Training and validation loss are key metrics to track model learning with Functional API; precision and recall guide task-specific performance.