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

    Non-negative Matrix Factorization

    Non-negative Matrix Factorization — Parts-based factorization for non-negative data.

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

    Introduction

    Non-negative Matrix Factorization — Parts-based factorization for non-negative data. This lesson pairs the idea with a minimal Python/sklearn workflow you can extend in a notebook.

    Understanding the topic

    Concept Parts-based factorization for non-negative data.

    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 — Parts-based factorization for non-negative data.
    • 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 — Parts-based factorization for non-negative data.
    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
    from sklearn.datasets import load_digits
    from sklearn.decomposition import NMF
    X, _ = load_digits(return_X_y=True)
    nmf = NMF(n_components=12, init="nndsvda", max_iter=500, random_state=42)
    W = nmf.fit_transform(X)
    print(f"W shape: {W.shape} | H shape: {nmf.components_.shape} | Frobenius reconstruction error: {nmf.reconstruction_err_:.2f}")

    Output

    W shape: (1797, 12) | H shape: (12, 64) | Frobenius reconstruction error: 891.34

    Execution workflow

    1Non-negative Matrix Factorization — workflow
    1 / 3

    Concept

    Parts-based factorization for non-negative data.

    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 Non-negative Matrix Factorization on a sample dataset
    • Write down one metric that proves the technique helped

    Summary

    Non-negative Matrix Factorization: Parts-based factorization for non-negative data.

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