4 Machine Learning Basics

Learn how machine learning projects move from task definition and data preparation through model evaluation and monitoring, and how to recognize common sources of error.

What does

(ML) uses data to build a model—a function that produces predictions or identifies patterns. A typical project defines a problem, collects and prepares data, fits a model, evaluates it on unseen examples, and monitors its performance after use.

The project workflow

A project begins by specifying what the model should predict or discover, who will use the result, and how success will be measured. For example, a delivery company might predict a package’s arrival time from its origin, destination, shipping method, and dispatch time.

When collecting and inspecting data, check whether examples are relevant, sufficiently representative, and correctly recorded. In , also check whether the target labels actually measure the outcome the project cares about.

Prepare data by handling missing values, errors, duplicates, and categorical variables, and by selecting or creating useful features. Split the data before learning preprocessing steps so information from evaluation examples cannot leak into training.

Train candidate models on training data, then use validation data to compare choices such as model type and . Reserve a separate test set for a final estimate of performance on new examples, and choose evaluation metrics that reflect both the task and the consequences of different errors.

After deployment, monitor whether real-world data or outcomes change over time. A model that performed well previously may need review or retraining.

Learning with and without labels

In , each example pairs input features with a known target label. The model learns a relationship between the features and labels so it can predict targets for new examples.

Two common supervised tasks differ by the kind of target they predict:

  • predicts a numerical quantity, such as delivery time or house price.

  • predicts a category, such as whether a transaction is fraudulent.

works with data that has no target labels to predict. It looks for structure in the features; for example, it may group customers with similar purchasing patterns into clusters. A discovered cluster is not automatically meaningful: people must interpret it in context.

Fitting models and generalizing

During fitting, training adjusts learned from data, such as the weights in a linear model, to reduce , a numerical measure of prediction error. Optimization methods such as make repeated parameter updates in directions that reduce .

are chosen outside the fitting process and are typically tuned using validation data. Examples include a learning rate and a limit on model complexity.

A low training by itself does not show that a model will be useful. means making reliable predictions on new examples drawn from the conditions where the model will be used. Comparing performance on training and validation data helps reveal whether the model is learning useful patterns or failing to perform beyond its training examples.

Recognizing poor fit

means the model is too simple, poorly configured, or insufficiently trained to capture useful patterns; it performs poorly even on training data. means the model learns details or noise specific to training examples: training performance is strong, but performance on unseen examples is weaker.

A good fit balances learning useful patterns with avoiding unnecessary complexity. More data, a simpler model, regularization, or early stopping can sometimes reduce . Evaluation data should represent the real use case, and the test set should remain reserved for final assessment.

Common sources of error

Several problems can undermine model quality or make evaluation misleading:

  • Poor or unrepresentative data: Missing values, incorrect measurements, duplicates, or underrepresented groups can distort what the model learns.

  • Noisy or misleading labels: Labels may contain mistakes or may be only an imperfect proxy for the outcome the project cares about.

  • : Information unavailable at prediction time, or information from validation or test data, enters training or preprocessing. This can make evaluation results look better than real performance. Learn preprocessing rules from training data, then apply those same rules to the other splits.

  • Weak features or unsuitable model choices: Available inputs may not contain enough information, or the model may be too simple or unnecessarily complex for the task.

  • Poorly designed evaluation: A metric can obscure important failures. Accuracy alone, for example, may hide poor detection of a rare but important class. Choose metrics that match the goal and the costs of different errors.

  • : Real-world inputs or outcomes may differ from the training data or change over time. Performance measured on an old test set may not reflect current use.

  • Optimization difficulties: Training may not adequately reduce , for instance because the learning rate or other training settings are unsuitable.

Putting the workflow together

A sound project defines its task, prepares appropriate data, fits models on training examples, tunes choices on validation data, and reserves test data for final evaluation. predicts labeled targets, while searches for structure without target labels.

A model is valuable when it generalizes to relevant new data. Assess fit and evaluation carefully, and watch for leakage, biased or noisy data, unsuitable metrics, optimization problems, and changes in real-world conditions.