Skip to main content

wNMF: Weighted Non-Negative Matrix Factorization

About

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

Installation

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 https://github.com/asn32/weighted-nmf.git
$ cd weighted-nmf
$ python3 setup.py install --user

Usage

wNMF is a python library that can be imported.

from wNMF 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
n=100
features = 100
components=25
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,
            beta_loss='kullback-leibler',
            max_iter=1000,
            track_error=True)

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

fit = model.fit(X=X,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

License

wNMF is MIT-licensed

Disclaimer

wNMF is provided with no guarantees

Release files for wNMF 0.0.42

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wNMF 0.0.42
File Size Uploaded
wNMF-0.0.42.tar.gz 12.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for wNMF 0.0.42
File Interpreter ABI Platform
wNMF-0.0.42-py3.8.egg Legacy Egg format - - Details
wNMF-0.0.42-py3-none-any.whl Python 3 none any Details

Total release size: 41.7 kB

Release files / wNMF-0.0.42.tar.gz

Download URL wNMF-0.0.42.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d5b3168f6d788d5079119327cafd43e84986e185ec8265cffad5dbf3391ceba3
BLAKE2b-256 checksum
How to use checksums
fd599b418824f83b41c8d0d6c5f7f079836790be9b47332828afae798ad661f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.3

Release files / wNMF-0.0.42-py3.8.egg

Download URL wNMF-0.0.42-py3.8.egg
Size 18.7 kB
Tags Egg
SHA-256 checksum
How to use checksums
c38382f2755090816bc0c6ee8e4322e2e61ce86faf4e1e5c201a1ea73388a9fc
BLAKE2b-256 checksum
How to use checksums
18e2f175952e869686c9741060567559bc12e00314a972c36d10b582682bc3e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.3

Release files / wNMF-0.0.42-py3-none-any.whl

Download URL wNMF-0.0.42-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab759baf44f3652a62db01603cd5359d50cfd7a24ef9694650a0bb48b2e9b591
BLAKE2b-256 checksum
How to use checksums
b7754b3ce4d67216bcefb3a854f4002312bdce61a381efc47e4bd4a67467d594
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.0.42 This release

3 release files

0.0.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page