Imagine you have an AI model that predicts loan approvals. Why should you validate the input data before feeding it to the model?
Think about what happens if the model gets unexpected or wrong data.
Input validation helps catch errors or unexpected values early. This prevents the AI from making wrong predictions or crashing.
What is the output of this Python function that sanitizes input text by removing digits?
def sanitize(text): return ''.join(c for c in text if not c.isdigit()) result = sanitize('Agent007 is ready!') print(result)
Look at how digits are filtered out from the string.
The function removes all characters that are digits. So '007' is removed from 'Agent007'.
You have input data that may contain some errors or noise. Which model type is best to handle this situation?
Think about models that include techniques to reduce overfitting and handle noise.
Deep neural networks with dropout and batch normalization help the model generalize better and reduce sensitivity to noisy inputs.
You trained two models: one on raw input data and one on sanitized input data. The sanitized model has 5% higher accuracy. What does this suggest?
Think about how cleaning data affects learning.
Removing noise or invalid data through sanitization helps the model focus on meaningful patterns, improving accuracy.
Consider this code snippet that validates numeric input features before prediction. What error will it raise?
def validate_features(features): for key, value in features.items(): if value < 0: raise ValueError(f"Negative value for {key}") input_data = {'age': 25, 'income': -5000, 'score': 70} validate_features(input_data)
Check which input value is negative and what the function does.
The function raises a ValueError when it finds a negative value. 'income' is -5000, so the error message mentions 'income'.
