You are previewing Programming Collective Intelligence.

# Non-Negative Matrix Factorization

The technique for extracting the important features of the data is called non-negative matrix factorization (NMF). This is one of the most sophisticated techniques covered in this book, and it requires a bit more explanation and a quick introduction to linear algebra. Everything you need to know will be covered in this section.

## A Quick Introduction to Matrix Math

To understand what NMF is doing, you'll first need to understand a bit about matrix multiplication. If you're already familiar with linear algebra, you can safely skip this section.

An example of matrix multiplication is shown in Figure 10-2.

This figure shows how two matrices are multiplied together. When multiplying matrices, the first matrix (Matrix A in the figure) must have the same number of columns as the second matrix (Matrix B) has rows. In this case, Matrix A has two columns and Matrix B has two rows. The resulting matrix (Matrix C) will have the same number of rows as Matrix A and the same number of columns as Matrix B.

The value for each cell in Matrix C is calculated by multiplying the values from the same row in Matrix A by the values from the same column in Matrix B and adding all the products together. Looking at the value in the top left corner of Matrix C, you can see that the values from the first row of Matrix A are multiplied by ...