# Non-Negative Matrix Factorization in Machine Learning

Non-Negative Matrix Factorization (NNMF) is a group of machine learning algorithms used in multivariate analysis and linear algebra. It is used in place of PCA when the dataset is composed of non-negative items. If you don’t know anything about the concept of NNMF, this article is for you. In this article, I’ll give you an introduction to non-negative matrix factorization in machine learning its implementation using Python.

## Non-Negative Matrix Factorization

Non-negative matrix factorization (NNMF) is also known as a non-negative matrix approximation. When the features of a dataset are having non-negative elements, then it is possible to use NNMF instead of the standard principal component analysis. NNMF is composed of a group of algorithms where a matrix is factored into two matrices W and H with a property that no matrix has negative elements.

The NNMF approach is therefore very effective for image and text datasets where there are no negative elements. The algorithm works by setting random values for W and H until both W and H become stable.

## Implementation of NNMF using Python

NNMF is used instead of principal component analysis when the dataset contains non-negative items. The main difference between NNMF and PCA is that in PCA we have no constraint on the explained variance even though the matrices are non-negative. Now let’s see how to implement it using the Python programming language. Here I will be using the NNMF approach on the iris dataset:

```Output:
[5.09930918 3.50128354 1.40077688 0.19798814]```

## Summary

So this is how we can use the NNMF approach with Python using the scikit-learn library. NNMF is a group of machine learning algorithms used in multivariate analysis and linear algebra. It is used in place of principal component analysis when the dataset contains non-negative items. Hope you liked this article on an introduction to Non-Negative Matrix Factorization (NNMF) in Machine Learning and its implementation using Python. Please feel free to ask your valuable questions in the comments section below. ##### Aman Kharwal
Coder with the ♥️ of a Writer || Data Scientist | Solopreneur | Founder
Articles: 1102