Types of Learning
Topic — The single most consequential architectural decision in machine learning is determined by one question: Do you have target labels ()? The presence, absence, or scarcity of ground-truth labels determines your learning paradigm - supervised, unsupervised, semi-supervised, or self-supervised - and dictates which algorithms are mathematically valid.
1. Feature Matrices vs. Target Vectors
In machine learning, data is represented by an input matrix and an optional target vector :
┌──────────── Features (X) ────────────┐ ┌─ Target (y) ─┐
Clump Uniformity Marginal Diagnosis
thickness of cell size adhesion
sample 1 5 1 1 benign
sample 2 5 4 5 benign
sample 3 3 1 1 malignant
| Mathematical Symbol | Industrial Term | Linear Algebra Shape | Description |
|---|---|---|---|
| Feature Matrix | 2-D: | All measured predictor variables across samples and features. | |
| Target Vector | 1-D: | Ground-truth labels or continuous outcomes we wish to predict. | |
| Sample | Row / Instance | 1-D: | A single observed entity (e.g. one patient or one transaction). |
| Feature | Attribute / Predictor | Column | One measured property of that entity. |
The Whole Paradigm Fork in One Question
- Do you have a target column for all rows? Supervised Learning.
- Do you have NO target column ? Unsupervised Learning.
- Do you have a target column for only a small subset of rows? Semi-Supervised Learning.
2. Interactive Feature Subtype Classifier
Machine learning features split into numeric (quantitative) and categorical (qualitative) types, each branching into two crucial sub-types:
Feature Data Subtype Classifier
Select a real-world variable to inspect its mathematical properties and Scikit-Learn encoding strategy:
Categorical
Ordinal
No (cannot average)
OrdinalEncoder (0, 1, 2)The Target Rule Worth Memorising
When setting up your data architecture:
The data used to make predictions - the features () - can be a mixture of numeric and categorical variables. But the output - the target () - alone dictates the technique: if is continuous numeric, it is Regression; if is categorical, it is Classification.
3. The Positive Class Convention in Binary Classification
In binary classification (), the two classes are mathematically asymmetric:
- Positive Class (): The specific outcome you are actively searching for (e.g. presence of disease, fraudulent charge, spam email, customer cancellation).
- Negative Class (): The baseline, ordinary, default "nothing to report" state (e.g. healthy, legitimate, non-spam, retained).
The "Positive != Good" Trap and Library Defaults
- "Positive" has nothing to do with being socially or clinically good. In medical oncology, having a malignant tumor is the positive class (a positive test result).
- Scikit-Learn defaults to alphanumeric sorting. In Scikit-Learn's built-in Breast Cancer dataset, label
1is assigned tobenign(healthy) because "benign" comes before "malignant" alphabetically. - If you compute
recall_score()without overridingpos_label, your model measures how well it finds healthy patients, completely missing the clinical question ("how well do we catch cancer?"). Always verify your label mapping.
4. Interactive Label Supervision Spectrum
Adjust the label availability slider to observe how machine learning paradigms transition from pure unsupervised exploration to fully supervised learning:
Label Supervision Spectrum Explorer
Move the slider to simulate varying levels of available ground-truth labels:
A small pool of verified labels (1-20%) bootstraps a large pool of unlabeled data via self-training or pseudo-labeling.
Evaluated against the holdout labeled test set. Success relies strictly on the cluster assumption.
5. The Four Learning Paradigms in Depth
- 1. Supervised Learning
- 2. Unsupervised Learning
- 3. Semi-Supervised Learning
- 4. Self-Supervised Learning (SSL)
- Data Requirement: Every single training row contains input features and ground-truth answer .
- The Workflow: Fits mathematical weights by minimizing the residual loss between predicted and true .
- Key Advantage: Direct, objective validation on an isolated test set (, Accuracy, ROC-AUC).
- Core Branches:
- Classification: Target is categorical ().
- Regression: Target is continuous ().
- Data Requirement: Contains only input features . No target vector exists.
- The Workflow: Discovers geometric patterns, high-density manifolds, and clusters.
- Core Families:
- Clustering: Grouping rows into unnamed clusters (
KMeans,DBSCAN). - Dimensionality Reduction: Compressing wide feature spaces (
PCA,t-SNE). - Density Estimation: Modeling the probability density to flag anomalies.
- Clustering: Grouping rows into unnamed clusters (
- Evaluation Challenge: Has no objective accuracy. Groupings require domain expert sign-off.
- Data Requirement: A small subset of labeled data combined with a massive pool of unlabeled data .
- The Self-Training Loop:
- Train a model on the small labeled set .
- Predict on the unlabeled set .
- Select the most confident predictions and pseudo-label them.
- Retrain on the expanded dataset and repeat.
- The Cluster Assumption: Assumes data points close to each other in feature space share the same class label. If this fails, self-training amplifies its own errors!
- The Modern Paradigm: The foundation of modern Large Language Models (LLMs) and vision transformers.
- Mechanism (The Data is its own Label):
- Masked Modeling (e.g. BERT): Hides tokens in sentences and trains the network to predict the masked word.
- Autoregressive Generation (e.g. GPT): Predicts the next token in sequence.
- Representational Learning: Produces high-dimensional embeddings that are subsequently fine-tuned with a tiny supervised dataset.
6. Implementation Lab
Lab Exercise: Three Paradigms on the Breast Cancer Dataset
An interactive, fully functional Google Colab / Jupyter Notebook is available to run Supervised, Starved Supervised (30 labels), Semi-Supervised (SelfTrainingClassifier), and Unsupervised (KMeans) on the exact same 426-patient dataset live in your browser.
How to run the lab:
- Click the "Open In Colab" badge above to launch the interactive notebook.
- Run cells sequentially to benchmark accuracy across varying label counts.
Key Experiments to Run:
- Experiment 1 (The Starved Supervised Baseline): Compare fully supervised accuracy (, 426 labels) against starved supervised (, 30 labels) to measure the value of 396 additional annotations.
- Experiment 2 (Semi-Supervised Lift Test): Run
SelfTrainingClassifieron the 30 labels plus 396 unlabeled rows and observe why semi-supervised lift is small () on well-separated datasets. - Experiment 3 (Unsupervised Agreement vs. ARI): Observe KMeans achieving raw agreement with zero labels, but check Adjusted Rand Index () to see why raw accuracy on clusters is misleading.
7. Common Mistakes
- 1. Believing Positive Means Good
- 2. Integer Encoding Nominal Categories
- 3. Measuring Accuracy on Unsupervised Clusters
- 4. Semi-Supervised Learning is Free Accuracy
- The Misconception: "The positive class in binary classification represents the desirable medical or business outcome."
- Wrong Thinking: Designating healthy patients as the positive class.
- The Right Principle: The positive class is the target condition you are actively seeking to detect (cancer, fraud, churn). It is named after a positive test result, not moral or medical goodness.
- The Misconception: "We can encode colors as Red=0, Green=1, Blue=2 for linear regression."
- Wrong Thinking: Imposing false ordinal relationships on nominal categories.
- The Right Principle: Only Ordinal variables (Low/Med/High) possess a natural rank. Nominal variables must be One-Hot encoded; otherwise, models assume Blue is twice as large as Green!
- The Misconception: "Our KMeans clustering model achieved 91% accuracy."
- Wrong Thinking: Comparing arbitrary cluster IDs () directly to true classes with standard classification accuracy.
- The Right Principle: Clustering has no predefined ground-truth labels. Cluster numbers are arbitrary. Use the Adjusted Rand Index (ARI) to evaluate pair-wise clustering alignment while correcting for random chance.
- The Misconception: "Adding unlabeled data to our training set will always improve model score."
- Wrong Thinking: Expecting self-training to consistently lift performance.
- The Right Principle: Semi-supervised learning only succeeds when data conforms to the cluster assumption. If early pseudo-labels are incorrect, self-training reinforces its own errors and actively degrades accuracy.
8. Summary
Feature Subtypes
- Numeric Continuous: Infinite precision scale (Height, Temperature).
- Numeric Discrete: Countable integers (Bedrooms, Ticket count).
- Categorical Nominal: Unordered labels (Color, Zip code). Needs One-Hot.
- Categorical Ordinal: Natural ranking (Low/Med/High). Integer encodable.
The Four Paradigms
- Supervised: 100% labeled . Classification & Regression.
- Unsupervised: 0% labels. Discovers clusters, projections (KMeans, PCA).
- Semi-Supervised: Few labels + abundant unlabeled data (Self-training).
- Self-Supervised: Pre-text prediction tasks on raw data (LLMs, BERT).
Key Takeaways
- Target Alone Decides: Features () can be a mixture of numeric and categorical data; the target variable () alone dictates whether the problem is Classification or Regression.
- Watch pos_label: Scikit-Learn defaults to alphabetical label ordering, which frequently maps the negative class to 1. Always set
pos_labelexplicitly. - Clustering != Classification: Clustering proposes unnamed geometric segments; it cannot be evaluated using classification accuracy.
Next Section: Reinforcement Learning - learning through environment states, actions, rewards, and policy optimization without a static dataset.
9. Active Recall
Test your understanding by answering first, then clicking to reveal the underlying principles.
Interactive Checkpoint Quiz
Interactive Checkpoint: The Nominal Encoding Trap
A data scientist encodes postal Zip Codes (e.g. 90210, 10001) as standard continuous integers in a linear regression model. What is the fundamental statistical error?
Review Flashcards
1. [THEORY] Why is the "positive class" in medical diagnostics designated as having the disease?
- Positive Test Detection: "Positive" refers to a positive detection outcome (the condition was detected), not moral goodness.
- Asymmetric Priority: Having cancer is the rare, consequential event. Downstream evaluation metrics (like Precision, Recall, and F2-Score) are formulated around the positive class to measure how reliably critical cases are captured.
2. [ANALYZE] In Scikit-Learn's built-in Breast Cancer dataset, label 1 is benign. What dangerous bug occurs if you evaluate recall without checking?
- The Inverted Evaluation: Scikit-Learn treats label
1as the default positive class. - Calling
recall_score(y_test, y_pred)evaluates the model's ability to find healthy (benign) patients! - A high score () gives false confidence, while the critical life-or-death clinical question ("how many malignant tumors were caught?") remains completely unmeasured. Always specify
pos_label=0or re-map labels.
3. [THEORY] What is the "cluster assumption" in semi-supervised learning, and what happens when it fails?
- The Cluster Assumption: Assumes that data points lying close together in feature space or within the same high-density cluster share the same class label.
- Failure Consequence: If classes overlap or clusters do not align with target boundaries, self-training assigns pseudo-labels to incorrect points with high confidence, amplifying errors and producing accuracy worse than trained on the small labeled set alone.
4. [MATH] Why is standard accuracy misleading when evaluating KMeans clustering, and what metric should be used instead?
- Arbitrary Indexing & Chance Agreement: Clustering assigns arbitrary IDs (Cluster 0, Cluster 1) with no concept of ground-truth names. Standard accuracy does not account for label permutation or random alignment.
- The Solution: Use the Adjusted Rand Index (ARI). ARI evaluates whether pairs of samples are placed in the same or different clusters and corrects for chance agreement, ensuring random clustering scores exactly
0.0.
5. [THEORY] How does Self-Supervised Learning (SSL) differ from traditional Unsupervised Learning?
- Unsupervised Learning: Seeks to discover flat geometric clusters (KMeans) or low-dimensional projections (PCA) directly from raw features without predictive supervision.
- Self-Supervised Learning: Automatically constructs predictive pretext tasks from the data itself (e.g. masking words in BERT or predicting the next token in GPT). It trains via supervised backpropagation against internal data structure to learn deep universal representations.