Which statement best describes the main difference between machine learning and traditional programming?
Think about how each approach gets its instructions.
Machine learning models learn from examples (data) to make predictions. Traditional programming follows fixed rules written by programmers.
Given the following code snippets, what is the output of the machine learning model prediction compared to the traditional rule-based function?
def rule_based(x): if x > 5: return 'High' else: return 'Low' class SimpleModel: def predict(self, x): return 'High' if x > 3 else 'Low' input_value = 4 print(rule_based(input_value)) model = SimpleModel() print(model.predict(input_value))
Check the conditions in both functions carefully.
The rule-based function returns 'Low' for input 4 because 4 is not greater than 5. The ML model returns 'High' because it uses a threshold of 3.
You want to build a system that detects spam emails. Which approach is more suitable and why?
Consider how spam changes over time.
Spam patterns evolve, so machine learning can adapt by learning from new examples, unlike fixed rules.
You test a traditional program and a machine learning model on 100 samples. The traditional program correctly classifies 80 samples, and the ML model correctly classifies 90 samples. What are their accuracies?
Accuracy is the number of correct predictions divided by total samples.
Accuracy = (correct / total) * 100. So 80/100 = 80%, 90/100 = 90%.
Given the code below, why does the machine learning model prediction raise an error while the traditional function works fine?
def traditional_func(x): return 'Positive' if x > '0' else 'Non-positive' class MLModel: def predict(self, x): return x > 0 input_value = '5' print(traditional_func(input_value)) model = MLModel() print(model.predict(input_value))
Check the data types used in comparisons.
Comparing a string '5' with integer 0 using '>' causes a TypeError in the ML model. The traditional function compares the string '5' to the string '0', so it does not raise an error.
