Skip to main content
PProfileMatch

What Is Machine Learning? How to Frame a Problem (and When Not To)

Machine LearningLesson 1 of 45 min read

What you'll learn

  • Explain machine learning as searching for parameters that fit labelled examples
  • Turn a vague business request into a target, inputs, a prediction moment and a metric
  • Build a majority-class baseline and a one-parameter learned rule in Python
  • Recognise problems where rules, SQL or a spreadsheet beat machine learning

On this page

  1. Rules versus learning
  2. Framing the problem before touching data
  3. When not to use machine learning
  4. Common mistakes and the symptoms they cause
  5. How this shows up in real projects and interviews

A city bike-share operator asks a simple question: "Can we predict which stations will run out of bikes by 6pm so a van can top them up before the evening rush?" Nobody can write the rule by hand. It depends on the neighbourhood, the weather, the day of the week and how many bikes were there that morning. This is the situation machine learning exists for: you cannot state the rule, but you have thousands of past examples where the outcome is known.

Rules versus learning

In ordinary programming you write the rule and the computer applies it to data. In machine learning you supply the data and the correct answers, and an algorithm searches for the rule. The rule it finds is called a model; the numbers inside it are its parameters; and the process of finding them is training. Nothing about this is mystical. Training is a search for the parameter values that make the fewest mistakes on examples you already have.

To make that concrete, here is the smallest possible model: a single threshold on the number of bikes at 8am. The "learning" is trying every threshold and keeping the one with the fewest mistakes. Before that, we compute a baseline: what a model that always answers "no, it will not run empty" would score. Any model worth keeping has to beat it.

threshold_model.py
# Bike-share question: will this station run out of bikes before 6pm?
# Each row: (bikes_at_8am, ran_empty_by_6pm)  1 = yes
history = [
    (2, 1), (3, 1), (4, 1), (4, 1), (5, 0), (6, 1), (6, 0), (7, 0),
    (8, 0), (9, 0), (10, 0), (11, 0), (12, 0), (14, 0), (3, 1), (5, 1),
]

def errors_for_threshold(rows, t):
    """Predict 'will run empty' when the 8am count is t or lower."""
    wrong = 0
    for bikes, empty in rows:
        guess = 1 if bikes <= t else 0
        if guess != empty:
            wrong += 1
    return wrong

# Baseline: always say "will not run empty"
baseline_wrong = sum(1 for _, empty in history if empty == 1)
print(f"always-no baseline: {baseline_wrong} wrong of {len(history)}")

# "Learning": try every threshold, keep the one with the fewest mistakes
best_t, best_wrong = None, None
for t in range(0, 15):
    wrong = errors_for_threshold(history, t)
    print(f"  threshold <= {t:>2}: {wrong} wrong")
    if best_wrong is None or wrong < best_wrong:
        best_t, best_wrong = t, wrong
print("learned threshold:", best_t, "with", best_wrong, "wrong of", len(history))

# Stations the model has never seen
new_stations = [(3, 1), (5, 0), (6, 1), (8, 0), (2, 1), (7, 1)]
print("wrong on unseen stations:", errors_for_threshold(new_stations, best_t), "of", len(new_stations))

Output

always-no baseline: 7 wrong of 16
  threshold <=  0: 7 wrong
  threshold <=  1: 7 wrong
  threshold <=  2: 6 wrong
  threshold <=  3: 4 wrong
  threshold <=  4: 2 wrong
  threshold <=  5: 2 wrong
  threshold <=  6: 2 wrong
  threshold <=  7: 3 wrong
  threshold <=  8: 4 wrong
  threshold <=  9: 5 wrong
  threshold <= 10: 6 wrong
  threshold <= 11: 7 wrong
  threshold <= 12: 8 wrong
  threshold <= 13: 8 wrong
  threshold <= 14: 9 wrong
learned threshold: 4 with 2 wrong of 16
wrong on unseen stations: 2 of 6

Three honest lessons come out of this tiny run. First, the model beat the baseline (2 mistakes instead of 7). Second, thresholds 4, 5 and 6 tie, so the data cannot tell them apart and the answer depends on how ties are broken. Third, the error rate rose from 2 of 16 (12.5%) on the data it learned from to 2 of 6 (about 33%) on stations it had never seen. That gap between "fits what it studied" and "works on new cases" is the central theme of the whole field, and we return to it in the lesson on splits and overfitting.

Framing the problem before touching data

Most failed ML projects fail at framing, not at algorithms. Before any code, fill in a short sheet. Writing it down forces the vague request to become something a model can actually be trained and judged on.

problem framing sheet
DECISION   What will a person or system do differently?
           -> Send a rebalancing van to a station by 3pm.
TARGET     The exact thing to predict, as a column.
           -> ran_empty_by_6pm (yes/no), one row per station-day.
WHEN       The moment the prediction is made.
           -> 11:00am. Only data known at 11am may be used.
INPUTS     What we know at that moment.
           -> bikes at 8am, forecast rain, weekday, nearby events.
COST       What a wrong answer costs, in each direction.
           -> Missed shortage: angry riders. False alarm: wasted trip.
BASELINE   The simple method to beat.
           -> Always "no", or the same station's value last week.
METRIC     How success is measured (see the metrics lesson).
           -> Share of real shortages caught, at <= 1 false alarm in 3.

Notice the WHEN line. If you train on a column such as "bikes at 5pm" you would predict shortages perfectly in testing and be useless at 11am, because that number does not exist yet. This mistake is called leakage and we will return to it, but it is born at framing time, which is why the sheet asks for it explicitly.

When not to use machine learning

SituationBetter choiceWhy
The rule is known and stable (tax bands, shipping zones)Plain code or a lookup tableA model would only approximate what you can state exactly
You need an answer you can fully explain or auditRules, or a very simple modelComplex models are hard to justify case by case
Only a handful of examples existJudgement, or a rule of thumbToo little data to separate signal from noise
The question is "what happened", not "what will happen"SQL and a chartDescriptive questions need aggregation, not prediction
No data about the outcome is ever recordedStart collecting it firstA model cannot learn a label nobody captured

Common mistakes and the symptoms they cause

  • No baseline. You report "90% accuracy" with no reference, and a stakeholder later discovers that always answering "no" scores 90% as well. The symptom is a model that looks impressive in a slide and changes nothing in practice.
  • Vague target. "Predict churn" without defining the window (cancels within 30 days? 90?) produces a label that different people compute differently, so results cannot be reproduced.
  • Using information from the future. A feature that is recorded after the prediction moment gives near-perfect test scores and collapses on the first live day.
  • Evaluating on the data you trained on. In the run above the error rate looked three times better on the history than on new stations.

How this shows up in real projects and interviews

In a real project, the first week is usually spent on the framing sheet and on locating a trustworthy label, and very little on algorithms. In interviews for data and ML roles, "how would you approach predicting X?" is a framing question in disguise: expect to be asked what the target is, what is known at prediction time, what the baseline is and how you would measure success. Candidates who start with "I would train a neural network" lose points; candidates who ask about the decision and the cost of each kind of error gain them. If you want a general method for tackling open-ended questions, A Practical Problem-Solving Framework pairs well with the sheet above.

Try it yourself

Pick a decision from your own work or study (for example which support tickets need a same-day reply, or which library books will be overdue). Fill in the framing sheet with a precise target, the moment of prediction, at least four inputs that are known at that moment, the cost of each type of error, and a baseline. Then write 10 made-up rows and reproduce the threshold search from this lesson on a single input column.

Show a hint

If one of your inputs is only known after the outcome, it is not allowed. Check each input against the WHEN line before you accept it.

Key takeaways

  • A model is a rule found by searching for parameters that fit labelled examples; training is that search.
  • Always compute a baseline first (always-no, last week's value, a simple rule); a model must beat it to matter.
  • Frame the task with a decision, a precise target, the prediction moment, inputs, costs and a metric.
  • Do not use ML when the rule is known, the data is tiny, or the question is descriptive rather than predictive.

Test yourself

A trick from this lesson's ride: Beat the lazy baseline first: if answering 'no' for everyone scores 95%, then 95% is zero skill. Four more tricks like it wait along the route, each followed by a question.

Ride this lesson

Frequently asked questions

What is machine learning in simple terms?

Machine learning is a way of getting a program to find its own rule from examples instead of being given the rule. You provide inputs together with the correct answers, an algorithm adjusts its internal numbers to reduce mistakes, and you then use the result to predict answers for new inputs.

How do I know if a problem needs machine learning?

It is a good candidate when you cannot write the rule by hand, you have many past examples with known outcomes, the pattern is stable over time and a wrong prediction is affordable. If the rule is known, data is scarce or you only need a summary of the past, ordinary code or SQL is usually better.

What is a baseline in machine learning?

A baseline is a deliberately simple method, such as always predicting the most common answer or repeating last week's value, that your model must beat. It gives context to a score: 90% accuracy means little if guessing the majority class also gets 90%.