Machine learning is a branch of statistics and computer science that finds patterns in data and uses them to make decisions or predictions. Two major approaches are supervised learning and unsupervised learning. The key difference is whether the training data includes known answers, called labels.
This distinction matters because it determines what questions a model can answer and how its performance is evaluated.
In supervised learning, the model learns a mapping from inputs to outputs, such as predicting a house price from its features or classifying an email as spam or not spam. In unsupervised learning, the model receives inputs without labels and searches for hidden structure, such as clusters, similarities, or lower-dimensional patterns. Supervised methods are often used for prediction, while unsupervised methods are often used for exploration and data understanding.
Many real projects use both, for example clustering customers first and then training a supervised model for each group.
Key Facts
- Supervised learning uses labeled data: training examples have inputs x and known outputs y.
- Unsupervised learning uses unlabeled data: examples have inputs x but no target output y.
- A supervised model often learns a function written as y = f(x) + error.
- Classification predicts categories, such as spam or not spam, while regression predicts numbers, such as price or temperature.
- Clustering is an unsupervised task that groups similar data points based on a distance or similarity measure.
- A common supervised error measure is mean squared error: MSE = (1/n) sum(yi - yhat_i)^2.
Vocabulary
- Label
- A label is the known answer or target value attached to a training example, such as a class name or numerical outcome.
- Feature
- A feature is an input variable used by a model, such as height, age, color, income, or word count.
- Classification
- Classification is a supervised learning task in which the model predicts which category an example belongs to.
- Regression
- Regression is a supervised learning task in which the model predicts a numerical value.
- Clustering
- Clustering is an unsupervised learning task that groups data points so that points in the same group are more similar to each other than to points in other groups.
Common Mistakes to Avoid
- Calling every prediction problem unsupervised is wrong because prediction with known target answers is usually supervised learning.
- Using labels during clustering is wrong because standard clustering methods are meant to find groups without being told the correct group names.
- Treating classification and regression as the same task is wrong because classification predicts categories while regression predicts numerical values.
- Judging an unsupervised model only by accuracy is wrong because accuracy requires true labels, and unlabeled tasks often need measures such as silhouette score, reconstruction error, or human interpretation.
Practice Questions
- 1 A dataset has 1,000 emails, and each email is labeled spam or not spam. A model correctly classifies 920 emails. What is the accuracy as a percent?
- 2 For a regression model, the true values are 3, 5, and 10, and the predicted values are 2, 7, and 9. Compute the mean squared error using MSE = (1/n) sum(yi - yhat_i)^2.
- 3 A store has customer purchase histories but no labels such as budget shopper or premium shopper. Should the store begin with supervised or unsupervised learning to discover customer groups, and why?