ITD 140 · ML I
Module 1 · Reading

1.3 Traditional Programming vs. Machine Learning

Traditional Programming vs. Machine Learning

What you'll learn on this page
  • The fundamental flip between traditional code and ML
  • Why ML is useful for problems where rules are hard to write
  • When you should not reach for machine learning

The fundamental flip

Traditional Programming
Key Insight
In traditional programming, you write the rules. In machine learning, the computer writes the rules from examples you provide. This is the single most important conceptual shift in the course.

Worked example: Detecting spam

Suppose you want to build a spam filter. There are two paths:

Traditional approach ML approach
You sit down and write rules:
if "FREE" in subject.upper():
    return "spam"
if "viagra" in body.lower():
    return "spam"
if num_exclamation_marks > 5:
    return "spam"
# ... 200 more rules
return "not spam"
You collect 100,000 emails labeled spam / not-spam, hand them to scikit-learn:
model = LogisticRegression()
model.fit(emails, labels)
# Done. Model figured out the rules.
prediction = model.predict(new_email)
Problems: Spammers adapt. You'll be writing rules forever. Misses subtle patterns ("you've won" without exclamation marks). Wins: Adapts as you feed it new data. Catches patterns humans never thought to encode. Improves with more examples.

When ML is the right tool

ML shines when at least one of these is true:

  • The rules are hard to write explicitly. How do you write code that recognizes a cat in a photo? You can't — but you can show a model 10,000 cat photos.
  • The rules change over time. Spam, fraud, and recommendations all shift constantly. ML can be retrained; hand-coded rules go stale.
  • There's a lot of relevant data available. ML needs examples. No data, no model.
  • Approximate answers are acceptable. ML predictions have uncertainty. If you need exact, ML may not fit.

When ML is the wrong tool

Don't reach for ML if…
  • The rules are simple and stable. Calculating tax on a purchase doesn't need ML. Write the formula.
  • You don't have labeled data and can't get any. ML without data is just a wish.
  • You need 100% accuracy guarantees. A pacemaker shouldn't rely on a probabilistic model for "should I fire?"
  • The problem is small enough to brute-force. Don't train a model to find the maximum of three numbers.

Check your understanding

  1. For each problem, would you reach for traditional programming or ML?
    • Calculating an employee's overtime pay
    • Translating English to Spanish
    • Sorting a list of names alphabetically
    • Predicting which customers are about to cancel a subscription
    • Checking if a credit card number passes the Luhn checksum
Show answers
  • Overtime pay — traditional. Fixed formula, exact answer needed.
  • Translation — ML. Way too many rules and exceptions to hand-write.
  • Sorting — traditional. Already a solved algorithm.
  • Customer churn — ML. Patterns in customer behavior, lots of data available, approximate answers fine.
  • Luhn checksum — traditional. Exact algorithm; using ML here would be silly.