Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 111 ยท Getting Started

What Is Machine Learning?

Learn what machine learning is, how it differs from rules and statistics, the main learning types, key terms like features and labels, and when not to use it.

Machine learning (ML) is the practice of getting a computer to find a pattern in examples instead of being told the pattern. In ordinary programming you write the rules and feed in data to get answers. In machine learning you feed in data and answers, and the computer works out the rules. Those learned rules are called a model, and you can then apply the model to new data it has never seen.

This idea is useful whenever the rules are too many, too fuzzy or too changeable to write by hand. Nobody can list every rule that separates a spam email from a real one, but a program can learn the pattern from thousands of labeled emails. In this tutorial you will learn the ideas and the practical craft, using Python and scikit-learn, with every example running live in your browser.

Rules versus learning

Imagine you want to convert temperatures from Celsius to Fahrenheit. You know the rule, so you simply write it. Now imagine you only have a table of measurements and no formula. A learning algorithm can recover the rule from the table. Try both below.

Python A hand-written rule versus a learned rule

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The learned slope and offset come out as 1.8 and 32, the numbers in the textbook formula. The model was never told them. This case is a toy, because a formula exists. Machine learning earns its place when no formula exists, as with recognizing faces, predicting whether a customer will leave, or ranking search results.

The vocabulary

A handful of words appear in every lesson, so it pays to fix them now.

  • Sample (or example, row): one thing you observe, such as one customer or one house.
  • Feature (or input, predictor, column): a measurable property of a sample, such as the house's area in square meters. The features of all samples are stored in a table usually called X, with one row per sample and one column per feature.
  • Label (or target, output): the answer you want to predict, stored in y. The sale price of a house is a label.
  • Model: the learned function that maps features to a prediction.
  • Training: the step where the algorithm adjusts the model to fit the examples. In scikit-learn this is the fit call.
  • Prediction (or inference): using the trained model on new samples.

Two kinds of supervised problems appear so often that they have names. Regression predicts a number, such as a price or a temperature. Classification predicts a category, such as spam or not spam, or which digit is in an image.

The three main kinds of learning

How a model learns depends on what feedback it receives. The three families below cover almost everything, and the slides summarize them.

Supervised learning

Labeled examples Every training sample comes with the correct answer.
Regression Predict a number, like a price.
Classification Predict a category, like spam or not.

Most business ML is supervised, and it is the focus of this tutorial.

1 / 3

Supervised learning is the one you will use most. Unsupervised learning looks for groups and shapes in unlabeled data. Reinforcement learning learns by trial and reward; it needs a simulator or a live environment, which is why this tutorial concentrates on the first two. There are also in-between settings, such as semi-supervised learning, where only part of the data is labeled; see semi-supervised and active learning.

Here is the same data seen both ways. With labels, the model can learn to tell the groups apart. Without labels, an algorithm can still discover the groups.

Python Supervised versus unsupervised on the same points

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that the clustering step never saw y, yet it recovered groups of the same sizes. The cluster numbers it assigns are arbitrary, though; the model cannot know that a group should be called "class 2".

AI, machine learning, deep learning and data science

These four terms overlap, and people use them loosely. A useful way to keep them apart is as nested circles and a neighbouring field.

Term What it means Example
Artificial intelligence (AI) The broad goal of making machines do things that seem intelligent. It includes hand-written rules, search and planning as well as learning. A chess program using search and hand-tuned rules
Machine learning (ML) The part of AI where programs improve at a task by learning from data instead of following rules written by a person. A spam filter trained on labeled emails
Deep learning (DL) The part of ML that uses neural networks with many layers. It shines on images, audio and text, and usually needs a lot of data and computing power. An image classifier, a speech recognizer, a large language model
Data science A field about getting knowledge and decisions out of data: collecting and cleaning it, exploring it, statistics, visualization, modeling (often with ML) and communicating the results. An analyst explaining why sales fell and what to do about it

The relationship between data science and machine learning is the one that is most often misunderstood. Machine learning is a toolbox for building predictive models, and its success is measured by how well the model predicts on new data. Data science is a practice for answering questions with data, and ML is only one of its tools. A data scientist may spend most of a project on questions, data quality, statistics and interpretation and communication (explaining what a result means to people who must act on it), and use a machine learning model for only one step, or none at all. A machine learning engineer, in contrast, typically focuses on building, deploying and maintaining the models that learn from data.

A practical rule: if the main deliverable is a number, a chart or a recommendation for people, you are doing data science; if the main deliverable is a program that makes predictions automatically, you are doing machine learning. Most real projects need both, which is why this course covers the data side (exploration, cleaning, features, evaluation) as well as the algorithms.

Machine learning versus rules versus statistics

These three approaches overlap, and a good practitioner picks the simplest one that works.

Approach You provide Best when
Rules The logic itself The logic is known, stable and checkable, such as tax law or unit conversion
Statistics A question and a model of the world You need to explain or test why something happens, with confidence intervals
Machine learning Examples with answers You mainly need accurate predictions and the pattern is too complex to write down

Statistics and ML use many of the same tools, for instance linear regression. The difference is emphasis. A statistician usually cares about the meaning of a coefficient and whether an effect is real. A machine-learning engineer usually cares about how well the model predicts on data it has not seen. We keep both views in mind, and later lessons on multiple regression and feature importance show where they meet.

When machine learning is the wrong tool

Learning from data is powerful, but it is not free. Skip it, or at least start without it, in these situations.

  • A simple rule works. If "flag orders above $10,000" solves the problem, ship that. Rules are cheap, instant to explain and easy to audit.
  • You have little or no data. A model learns only what the examples show. Ten examples rarely support a reliable pattern.
  • The data does not contain the answer. If nothing in your features relates to the target, no algorithm can find a signal. A model trained on noise will happily produce confident noise.
  • Mistakes are very costly and you cannot tolerate any. ML models make errors by design, so there must be a safety net or a human check.
  • The world changes faster than you can retrain. A pattern that was true last year may be false now.
  • You must explain every decision in plain legal terms. Some models are hard to explain, which matters in lending or medicine.

A good habit before building any model: write down the simplest non-ML solution and measure it. That measurement becomes your baseline, and the model has to beat it to be worth keeping. See baselines and dummy models.

A model is also only as good as the question you ask it. "Will this customer cancel within 30 days?" is a precise, testable prediction. "Make our customers happier" is not a machine-learning problem until someone turns it into one.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In machine learning, what does the algorithm receive during training in a supervised problem?

    Supervised learning needs both inputs (features) and the known answers (labels) so it can learn the mapping between them.
  2. 2. A model predicts the price of a house in dollars. What kind of problem is this?

    Predicting a continuous number is regression. Classification predicts a category.
  3. 3. Which situation is the best candidate for a plain rule instead of machine learning?

    A conversion has an exact known formula, so learning it from data adds cost and error with no benefit.
  4. 4. KMeans was fitted on X only and found three groups. What kind of learning is that?

    No labels were used. The algorithm discovered structure in the unlabeled data, which is unsupervised learning.

Summary

  • Machine learning finds rules from examples; the learned rules form a model that predicts for new data.
  • Features (X) describe samples, labels (y) are the answers, and fit trains the model.
  • Supervised learning uses labels (regression for numbers, classification for categories); unsupervised learning looks for structure without labels; reinforcement learning learns from rewards.
  • Use rules when the logic is known, statistics when you need to explain effects, and ML when accurate prediction matters and the pattern is complex.
  • ML is the wrong tool when a simple rule works, data is scarce or uninformative, or errors cannot be tolerated.

Next: The Machine Learning Workflow