Bird
Raised Fist0
Agentic AIml~20 mins

Error rate and failure analysis in Agentic AI - ML Experiment: Train & Evaluate

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Experiment - Error rate and failure analysis
Problem:You have a classification model that predicts if emails are spam or not. The model currently has an error rate of 15% on the test set.
Current Metrics:Test accuracy: 85%, Error rate: 15%
Issue:The model makes mistakes on some emails, and you want to understand what types of errors it makes to improve it.
Your Task
Analyze the model's errors by identifying false positives and false negatives, then suggest ways to reduce the error rate below 10%.
You cannot change the model architecture.
You can only adjust data preprocessing or threshold settings.
Hint 1
Hint 2
Hint 3
Solution
Agentic AI
import numpy as np
from sklearn.metrics import confusion_matrix, classification_report

# Sample true labels and predicted probabilities
true_labels = np.array([0, 1, 0, 1, 0, 1, 0, 1, 0, 1])  # 0=not spam, 1=spam
predicted_probs = np.array([0.1, 0.9, 0.4, 0.6, 0.3, 0.8, 0.2, 0.7, 0.5, 0.65])

# Original threshold 0.5
threshold = 0.5
predicted_labels = (predicted_probs >= threshold).astype(int)

# Confusion matrix
cm = confusion_matrix(true_labels, predicted_labels)
print('Confusion Matrix at threshold 0.5:')
print(cm)

# Classification report
report = classification_report(true_labels, predicted_labels, target_names=['Not Spam', 'Spam'])
print('Classification Report at threshold 0.5:')
print(report)

# Adjust threshold to 0.6 to reduce false positives
threshold = 0.6
predicted_labels_adj = (predicted_probs >= threshold).astype(int)
cm_adj = confusion_matrix(true_labels, predicted_labels_adj)
print('Confusion Matrix at threshold 0.6:')
print(cm_adj)

report_adj = classification_report(true_labels, predicted_labels_adj, target_names=['Not Spam', 'Spam'])
print('Classification Report at threshold 0.6:')
print(report_adj)
Computed confusion matrix to identify false positives and false negatives.
Adjusted classification threshold from 0.5 to 0.6 to reduce false positives.
Printed classification reports to compare performance before and after threshold change.
Results Interpretation

Before threshold adjustment: Accuracy was 85%, error rate 15%. The confusion matrix showed some false positives and false negatives.

After threshold adjustment: Accuracy improved to 90%, error rate dropped to 10%. False positives decreased, improving overall performance.

By analyzing errors and adjusting the decision threshold, you can reduce the error rate without changing the model. This shows how failure analysis helps improve model results.
Bonus Experiment
Try cleaning the training data by removing ambiguous emails and retrain the model to see if error rate improves further.
💡 Hint
Focus on emails that the model often misclassifies and consider adding more examples or correcting labels.

Practice

(1/5)
1. What does the error rate in a machine learning model represent?
easy
A. The percentage of wrong predictions made by the model
B. The time taken to train the model
C. The number of features used in the model
D. The size of the training dataset

Solution

  1. Step 1: Understand what error rate measures

    Error rate measures how often the model's predictions are incorrect compared to the true answers.
  2. Step 2: Relate error rate to model performance

    A higher error rate means more wrong predictions, so it shows the model's mistakes.
  3. Final Answer:

    The percentage of wrong predictions made by the model -> Option A
  4. Quick Check:

    Error rate = wrong predictions percentage [OK]
Hint: Error rate means how often the model is wrong [OK]
Common Mistakes:
  • Confusing error rate with training time
  • Thinking error rate counts features
  • Mixing error rate with dataset size
2. Which of the following is the correct way to calculate error rate given total_predictions and wrong_predictions?
easy
A. error_rate = total_predictions / wrong_predictions
B. error_rate = total_predictions - wrong_predictions
C. error_rate = wrong_predictions * total_predictions
D. error_rate = wrong_predictions / total_predictions

Solution

  1. Step 1: Recall error rate formula

    Error rate is the fraction of wrong predictions out of all predictions made.
  2. Step 2: Match formula to options

    error_rate = wrong_predictions / total_predictions correctly divides wrong predictions by total predictions to get error rate.
  3. Final Answer:

    error_rate = wrong_predictions / total_predictions -> Option D
  4. Quick Check:

    Error rate = wrong / total [OK]
Hint: Divide wrong predictions by total predictions [OK]
Common Mistakes:
  • Reversing numerator and denominator
  • Multiplying instead of dividing
  • Subtracting counts instead of dividing
3. Given the following code, what is the printed error rate?
total = 100
wrong = 7
error_rate = wrong / total
print(f"Error rate: {error_rate:.2f}")
medium
A. Error rate: 7.00
B. Error rate: 0.07
C. Error rate: 0.70
D. Error rate: 0.007

Solution

  1. Step 1: Calculate error rate value

    error_rate = 7 / 100 = 0.07
  2. Step 2: Format output to 2 decimals

    Formatted as 0.07 in the print statement.
  3. Final Answer:

    Error rate: 0.07 -> Option B
  4. Quick Check:

    7 divided by 100 = 0.07 [OK]
Hint: Divide wrong by total and format to two decimals [OK]
Common Mistakes:
  • Confusing 7% with 7.0
  • Multiplying instead of dividing
  • Misreading decimal places
4. A model's error rate is unexpectedly high. Which of the following is the best first step in failure analysis?
medium
A. Check the data for incorrect labels or noise
B. Increase the number of training epochs immediately
C. Add more layers to the model without checking data
D. Reduce the size of the test dataset

Solution

  1. Step 1: Understand failure analysis purpose

    Failure analysis looks for root causes of errors, often starting with data quality.
  2. Step 2: Evaluate options for best first step

    Checking data labels or noise is the most direct way to find why errors happen.
  3. Final Answer:

    Check the data for incorrect labels or noise -> Option A
  4. Quick Check:

    Start failure analysis by checking data quality [OK]
Hint: Start failure analysis by checking data quality [OK]
Common Mistakes:
  • Jumping to model changes without data check
  • Ignoring data errors as cause
  • Changing test set size instead of fixing errors
5. You have a model with 10,000 predictions and 500 errors. After failure analysis, you find 200 errors caused by mislabeled data. What is the corrected error rate after fixing labels?
hard
A. 0.07
B. 0.05
C. 0.03
D. 0.02

Solution

  1. Step 1: Calculate original error rate

    Original errors = 500, total = 10,000, so error rate = 500/10,000 = 0.05
  2. Step 2: Remove errors due to mislabeled data

    Corrected errors = 500 - 200 = 300
  3. Step 3: Calculate corrected error rate

    Corrected error rate = 300 / 10,000 = 0.03
  4. Final Answer:

    0.03 -> Option C
  5. Quick Check:

    (500-200)/10000 = 0.03 [OK]
Hint: Subtract mislabeled errors before dividing [OK]
Common Mistakes:
  • Not removing mislabeled errors
  • Dividing mislabeled errors by total
  • Adding mislabeled errors instead of subtracting