ML versus deterministic rules
Quick answer
Machine learning (ML) builds a model from examples or experience rather than requiring a developer to specify every decision rule. It is useful when the desired output is measurable but the relationship between inputs and outputs is hard to write down. A rule is often better when the requirement is already exact.
A fixed temperature rule
A fictional storage room must trigger an alert at 8 degrees Celsius or higher. This policy is exact. The function takes a temperature and returns 1 for alert or 0 for no alert. In Python, int converts a true comparison to 1 and a false comparison to 0.
def alert(temperature): return int(temperature >= 8)
print(alert(7))print(alert(8))Expected output:
01The boundary is included because the policy says at least 8. No historical data or training is necessary.
A rule learned from examples
Suppose the goal changes to predicting whether a cooling unit will need maintenance tomorrow. The right threshold is unknown. In a toy training set, each pair contains a temperature and a later maintenance outcome (1 means yes). Compare two candidate thresholds and select the one with fewer mistakes. A loop counts correct predictions; the model is just the selected threshold.
rows = [(5, 0), (7, 0), (9, 1), (10, 1)]best_threshold = 6best_correct = -1for threshold in [6, 8]: correct = 0 for temperature, outcome in rows: if int(temperature >= threshold) == outcome: correct += 1 if correct > best_correct: best_threshold = threshold best_correct = correctprint(best_threshold)print(int(9 >= best_threshold))Expected output:
81Threshold 6 makes one mistake; threshold 8 makes none on these four examples. The selected rule predicts 1 at 9. This is a deliberately tiny model, not a validated maintenance system.
When not to use ML
A tax formula specified by policy, an exact file-size limit and a known eligibility rule normally need ordinary software. A forecast of next-day parcel delays may benefit from ML if representative data and measurable outcomes exist. Compare the cost of collecting data, maintaining the model and correcting errors with the simpler option.
A trained model can itself be deterministic during prediction. The difference is where its parameters come from, not whether it uses randomness.
Common mistake
Perfect predictions on training examples do not prove good predictions tomorrow. The examples used to choose the rule also make the rule look good. Evaluate on separate observations before relying on it.
Practice and next steps
Classify these three tasks: enforce a maximum parcel weight, predict a delivery delay, calculate a fixed shipping fee. Explain what data would be needed for the prediction. Next, identify the inputs and outcomes in a prediction dataset.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
ML versus deterministic rules — knowledge check
Apply the concepts from this lesson to small fictional scenarios.
A warehouse has an exact rule: reject weights over 20 kg. Which solution best implements it?
What changes when the maintenance threshold is learned?
For threshold 8 with alert at or above it, what happens at 8?
Why evaluate a learned threshold on new rows?
Which task is a reasonable ML candidate if suitable data exists?