Skip to main content

wNMF: weighted Non-Negative matrix Factorization

Project description

wNMF: Weighted Non-Negative Matrix Factorization


wNMF implements a simple version of Non-Negative Matrix Factorization (NMF) that utilizes a weight matrix to weight the importance of each feature in each sample of the data matrix to be factorized.

wNMF is easy to use, because it behaves like an sklearn.decomposition model, but also allows for multiple fitting attempts.

More information about the modified multiplicative update algorithim utilized can be found here: Blondel, Vincent & Ho, Ngoc-Diep & Van Dooren, Paul. (2007). Weighted Nonnegative Matrix Factorization and Face Feature Extraction

wNMF specifically implements solutions for determining the decomposed matrices U and V when minimizing the Frobenius Norm or the Kullback-Leibler Divergence:

Useful Links


This package is available on PyPI and can be installed with pip:

$ pip install wNMF

Alternatively, download the source from github and install:

$ git clone
$ cd weighted-nmf
$ python3 install --user


wNMF is a python library that can be imported.

import wNMF

And it can be used like an sklearn.decomposition model.

First create an instance of the wNMF model by setting the number of components.

Other parameters can be set too, such as the loss function, maximum number of iterations, and whether or not to track the decreasing error over every single run.

## Mock data, a 100x100 data matrix, reduce to 25 dimensions
features = 100
X = 100*np.random.uniform(size=n*features).reshape(features,n)
W = np.ones_like(X)

## Define the model / fit
model = wNMF(n_components=25,

Then, fit the model to the data using the instance methods wNMF().fit or wNMF().fit_transform.

fit =,W=W,n_run=5)

After the fit is complete, explore the fit quality by examining the decomposed matrices and / or overall error.

## Get the best solutions
lowest_error = fit.err)
best_V = fit.V
best_U = fit.U

## Or look at all the solutions from the 5 runs in this example
all_Vs = fit.V_all


wnmf is MIT-licensed


wnmf is provided with no guarantees

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for wNMF, version 0.0.4
Filename, size File type Python version Upload date Hashes
Filename, size wNMF-0.0.4-py3-none-any.whl (10.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size wNMF-0.0.4.tar.gz (11.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page