Machine Learning Tutorial 0/98 lessons ~6 min read Lesson 83

    Semi-Supervised Learning

    Semi-Supervised Learning — Exploit unlabeled mass when labels are costly.

    Course progress0%
    Focus
    9 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    Semi-Supervised Learning — Exploit unlabeled mass when labels are costly. This lesson pairs the idea with a minimal Python/sklearn workflow you can extend in a notebook.

    Understanding the topic

    Concept Exploit unlabeled mass when labels are costly.

    Workflow Load data → preprocess → fit or apply technique → measure on hold-out data.

    In practice Start with a small public dataset before jumping to proprietary production data.

    • Concept — Exploit unlabeled mass when labels are costly.
    • Workflow — Load data → preprocess → fit or apply technique → measure on hold-out data.
    • In practice — Start with a small public dataset before jumping to proprietary production data.

    Step-by-step explanation

    1. Concept — Exploit unlabeled mass when labels are costly.
    2. Workflow — Load data → preprocess → fit or apply technique → measure on hold-out data.
    3. In practice — Start with a small public dataset before jumping to proprietary production data.

    Informative example

    Python starter:

    python
    import numpy as np
    from sklearn.datasets import load_digits
    from sklearn.metrics import accuracy_score
    from sklearn.model_selection import train_test_split
    from sklearn.semi_supervised import LabelSpreading
    X, y = load_digits(return_X_y=True)
    X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.25, stratify=y, random_state=42)
    rng = np.random.default_rng(42)
    y_semi = y_tr.copy()
    y_semi[rng.random(len(y_tr)) < 0.85] = -1 # 85% unlabeled
    model = LabelSpreading(kernel="knn", n_neighbors=7).fit(X_tr, y_semi)
    print(f"Labeled count: {int((y_semi != -1).sum())}/{len(y_tr)} | Test Acc: {accuracy_score(y_te, model.predict(X_te)):.4f}")

    Output

    Labeled count: 202/1347 | Test Acc: 0.9556

    Execution workflow

    1Semi-Supervised Learning — workflow
    1 / 3

    Concept

    Exploit unlabeled mass when labels are costly.

    Best practices

    • Hold out a test set before hyperparameter tuning.
    • Scale numeric columns for distance-based models.
    • Track multiple metrics — not accuracy alone on skewed labels.

    Common mistakes

    • Leaking test statistics into preprocessing fit on full data.
    • Training on the same rows you report as test performance.
    • Chasing complex models before a simple baseline.

    Hands-on exercise

    Practice:

    • Apply Semi-Supervised Learning on a sample dataset
    • Write down one metric that proves the technique helped

    Summary

    Semi-Supervised Learning: Exploit unlabeled mass when labels are costly.

    Ready to mark this lesson complete?Track your journey across the entire course.