Supervised and Unsupervised Learning
Types of machine learning: classification and regression on labeled data, clustering on unlabeled data. Learn to evaluate a model on a test set and to fight overfitting.
All topics (1 of 3)
Chapter 1. Machine learning fundamentals
Chapter 2. Neural networks
Machine learning (ML) is an approach in which rules are learned from data instead of being written by hand. According to Tom Mitchell’s definition, a program learns if its performance on a task T, measured by P, improves with experience E. For example, in spam detection the experience is labeled emails and the measure is the share of emails classified correctly.
In supervised learning each training example comes with an answer (a label): the model learns the rule that maps an input x to an output y. If y is a discrete class (spam or not spam), the task is called classification; if it is a continuous number (a house price), it is regression. Well-known algorithms include linear regression, logistic regression (a classification algorithm despite its name), decision trees, support vector machines (SVM) and k-nearest neighbors (k-NN).
In unsupervised learning no answers are given: the model finds the hidden structure of the data by itself. The main tasks are clustering (grouping similar objects, for example segmenting customers with k-means), dimensionality reduction (PCA) and anomaly detection. The result is harder to evaluate because there is no correct answer, and conclusions often rely on an expert’s interpretation. There are also semi-supervised learning (a little labeled and a lot of unlabeled data) and reinforcement learning (an agent learns from rewards).
Model quality is evaluated only on data not seen during training, so the data is split into a training set and a test set (for example, 80% and 20%). If a model memorizes the training data and performs poorly on new data, this is called overfitting; a model that is too simple, on the other hand, underfits. Overfitting is fought with more data, a simpler model, regularization and cross-validation.
Key takeaways
- Machine learning learns rules from data instead of having them written by hand.
- Supervised learning has labeled data: classification (a discrete class) and regression (a continuous value).
- Unsupervised learning has no labels: clustering, dimensionality reduction and anomaly detection.
- Model quality is evaluated on a test set that was not used in training.
- Overfitting is when a model memorizes the training data and fails to generalize to new data.
Practice tasks
- Classify the following tasks as supervised (classification or regression) or unsupervised and justify your answer: sorting an email into spam, predicting tomorrow’s temperature, grouping customers by shopping habits, assigning an X-ray image to the class “healthy” or “sick”.
- In Python, split the
load_irisdata fromscikit-learn80/20 withtrain_test_split, train aKNeighborsClassifierand computeaccuracy_scoreon the test set. - On the same data, ignore the labels, run
KMeans(n_clusters=3)and compare the resulting clusters with the real species (for example, usingadjusted_rand_score).
Review questions
Test yourself: think first, then reveal the answer.
1How do classification and regression tasks differ?Show answerHide answer
In classification the result is a discrete class (spam or not spam); in regression it is a continuous number (a price, a temperature).2Why should a model be evaluated on the test set rather than the training set?Show answerHide answer
On the training set a model may simply memorize the data; only unseen data shows how it will work in new situations.3Which kind of learning does clustering belong to?Show answerHide answer
Unsupervised learning, because it does not require labels.
0 of 3 topics completed
Sign in to mark