1 Introduction to Machine Learning

Learn how machine-learning models use data, how common tasks and workflows differ, and how to evaluate whether a model performs well on new examples.

What machine learning does

Machine learning (ML) is a way to build software that learns patterns from data and uses them to make predictions or identify structure. Rather than writing a rule for every case, a developer chooses a learning method and supplies examples. The resulting model is a mathematical representation of patterns in the data.

Examples, features, and labels

A is a collection of examples. In a table, each row typically represents one example, and each column records a property of that example. A is an input property used by a model; features can be numerical, such as a home's floor area, or categorical, such as its neighborhood.

In , the value the model is asked to predict is called a or target. For example, a home-price might contain one row per home, features such as floor area and number of bedrooms, and a containing the sale price. Examples should be relevant to the task: errors, missing values, duplicates, or unrepresentative data can undermine a model's usefulness.

Common machine-learning tasks

The type of machine-learning problem depends on what the model should learn or produce.

  • predicts a numerical value. For example, a model might estimate a home's sale price from its features.

  • predicts a category. An email classifier might predict “spam” or “not spam.” It may first produce probabilities, then assign a category using a decision threshold.

  • groups similar examples when no known labels are supplied. A retailer could group shoppers with similar purchasing patterns. The groups are discovered from the data, and their meaning may need to be interpreted afterward.

and are common supervised-learning tasks: examples include labels, and the model learns to predict them. is a common unsupervised-learning task: the model looks for structure in examples without given labels.

From data to a model

A basic supervised-learning workflow connects the task definition, data preparation, model training, and evaluation.

  1. Define the task. Specify the prediction or pattern to find, and decide how success will be measured.

  2. Prepare the data. Collect relevant examples, select useful features, and address data-quality problems. Apply any needed transformations consistently.

  3. Split the . Set aside training data for learning and separate data for evaluation. A can help compare models and tune choices during development; reserve the for a final check. Exact split proportions depend on the data and task.

  4. Train a model. The learning algorithm uses the training examples to adjust the model so its predictions fit the examples according to a chosen objective, often called a .

  5. Evaluate and refine. Check performance on data not used to fit the model. Use validation results to guide changes, then evaluate the selected model on the .

  6. Use the model on new examples. Continue checking whether new data resembles the data used in development and whether performance remains acceptable.

For a home-price model, train on homes with known sale prices, then evaluate estimates on different homes whose prices are known but were withheld from training. This gives a better indication of performance on new homes than checking only the training examples.

Evaluating model performance

Evaluation asks whether a model works well for its intended task, not merely whether it has learned the training data. Choose metrics that reflect the consequences of errors.

  • : Mean absolute error (MAE) measures the average size of prediction errors. Mean squared error (MSE) penalizes larger errors more strongly.

  • : is the fraction of predictions that are correct. When classes are imbalanced or error types have different costs, precision and can give more useful information. For example, a medical screening system may need to avoid missing positive cases, making especially relevant.

  • : There may be no correct labels to compare against. Evaluation can consider whether groups are coherent and useful for the task, alongside suitable quantitative measures.

A metric is meaningful only in context. For example, a high score may be misleading if one class is much more common than another.

and

A model generalizes when it performs well on new examples, not just the ones it saw during training. occurs when a model fits peculiar details or noise in its training data too closely: it performs well on that data but poorly on unseen data. A model that performs poorly even on its training data may be underfit.

Comparing training and validation performance can help detect . If training performance keeps improving while validation performance worsens, the model may be fitting the training examples rather than learning patterns that generalize. Possible responses include simplifying the model, gathering more representative data, or using regularization.

Keep the separate from repeated model tuning. Repeatedly using it to make development choices can make its final evaluation less trustworthy.