7 Introduction to Machine Learning
Learn how machine learning uses labeled and unlabeled data, how models are trained and evaluated, and why evaluation must account for leakage, overfitting, and bias.
What does
builds programs that learn patterns from data and use them to make predictions or organize information. Rather than writing a rule for every case, a developer supplies examples and a learning algorithm. A resulting model is useful when it performs well on examples it has not seen before.
Learning from labeled examples
In , each training example includes input information called and a desired answer called a or target. The model learns a relationship between the inputs and targets, then uses that relationship to predict targets for new examples.
A housing dataset might include home size, neighborhood, and number of bedrooms as , with sale price as the target. A model could use those examples to predict prices for homes that have not yet sold.
predicts a numeric value, such as a home's price or tomorrow's temperature. measures the average absolute difference between predicted and actual values.
predicts a category, such as whether an email is spam or which plant species appears in a photo. A fraud model that predicts whether a transaction is fraudulent performs ; predicting the transaction's likely dollar loss is .
is the fraction of predictions that are correct. When classes are imbalanced, , the fraction of positive predictions that are correct, and , the fraction of actual positives found, can be more informative.
Finding structure without labels
In , examples have but no supplied target labels. The algorithm looks for structure in the data. Its results can help people explore a dataset, but a discovered pattern is not automatically meaningful or useful.
groups examples according to similarity. For example, a retailer might group customers by purchase patterns to explore different shopping behaviors. Other unsupervised methods reduce the number of dimensions used to represent data, making patterns easier to inspect or use in later analysis.
Because there may be no known correct answer, unsupervised results often require interpretation. A cluster score can measure properties such as how compact or separated groups are, but the score alone does not prove that the groups have real-world importance.
Separating training and evaluation
A is used to learn a model's patterns, while a held-out estimates how well the trained model may perform on new examples. For example, a dataset might be divided into training data and test data; the exact split depends on the problem and the available data.
For , keep each example's together with its when splitting the data. In , a can help preserve the proportions of each class in both sets. A random split may give an unrealistic evaluation when observations are related, such as multiple records from the same person, or ordered in time. In those cases, keep related groups together or, when that better matches the model's use, train on an earlier period and test on a later one.
Preprocessing requires the same care. If missing values are filled in or are scaled, learn those transformations using training data only, then apply them to the test data. Using test-set information during training or preprocessing causes and can make evaluation results overly optimistic.
A or can help compare model choices during development. Keep the for a final evaluation: repeatedly adjusting a model based on its test score can gradually make the part of the development process.
Choosing and interpreting evaluation measures
Choose evaluation measures to match both the task and the consequences of errors. For , MAE gives average error in the target's units. also measures prediction error, while giving relatively more weight to large errors.
For , gives the overall proportion of correct predictions. and describe different aspects of positive predictions, so the appropriate balance depends on the application. A screening system may prioritize finding as many true cases as possible, while another application may need to limit false alarms.
For , measures of within-group similarity and between-group separation can help compare results. Human review and domain knowledge are often needed to decide whether groups are useful. A score is only an estimate based on the chosen data, split, and metric; it does not guarantee that a model will perform equally well in every real-world setting.
Limits, , and
happens when a model learns training examples too closely, including random noise or accidental details, and then performs poorly on new data. A much better score on training data than on held-out data is one warning sign. Simpler models, more representative training examples, or other appropriate controls can help, but the right approach depends on the task.
A model can also : it fails to capture useful patterns and performs poorly even on its training data. Evaluation can help reveal both problems, but scores should be interpreted alongside the data and task.
can enter through the data, labels, measurement choices, or assumptions built into a system. If a training dataset underrepresents a population, contains historically biased decisions, or uses a misleading target, a model may repeat or amplify those problems. Overall performance can hide uneven errors across groups, so it can be important to examine data representation and evaluate results for relevant subgroups. No single metric or procedure guarantees fairness.
supports tasks such as and , while looks for structure in unlabeled data. Training and test sets help distinguish learning from evaluation, and validation approaches support model selection. Careful metric choice and avoiding leakage are important, but strong test performance does not eliminate risks from , biased data, or changes in conditions.