Skip to main content

wNMF: weighted Non-Negative matrix Factorization

Project description

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

Project details


Download files

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

Source Distribution

wNMF-0.0.42.tar.gz (12.0 kB view details)

Uploaded Source

Built Distributions

wNMF-0.0.42-py3.8.egg (18.7 kB view details)

Uploaded Egg

wNMF-0.0.42-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file wNMF-0.0.42.tar.gz.

File metadata

  • Download URL: wNMF-0.0.42.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for wNMF-0.0.42.tar.gz
Algorithm Hash digest
SHA256 d5b3168f6d788d5079119327cafd43e84986e185ec8265cffad5dbf3391ceba3
MD5 a75ec6087eca7b2122d0b117cb5c2b43
BLAKE2b-256 fd599b418824f83b41c8d0d6c5f7f079836790be9b47332828afae798ad661f0

See more details on using hashes here.

File details

Details for the file wNMF-0.0.42-py3.8.egg.

File metadata

  • Download URL: wNMF-0.0.42-py3.8.egg
  • Upload date:
  • Size: 18.7 kB
  • Tags: Egg
  • Uploaded using 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

File hashes

Hashes for wNMF-0.0.42-py3.8.egg
Algorithm Hash digest
SHA256 c38382f2755090816bc0c6ee8e4322e2e61ce86faf4e1e5c201a1ea73388a9fc
MD5 951c223498c571685670b9a41f006dd6
BLAKE2b-256 18e2f175952e869686c9741060567559bc12e00314a972c36d10b582682bc3e8

See more details on using hashes here.

File details

Details for the file wNMF-0.0.42-py3-none-any.whl.

File metadata

  • Download URL: wNMF-0.0.42-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for wNMF-0.0.42-py3-none-any.whl
Algorithm Hash digest
SHA256 ab759baf44f3652a62db01603cd5359d50cfd7a24ef9694650a0bb48b2e9b591
MD5 6c781b0ed440f5e7423b2097d90d8137
BLAKE2b-256 b7754b3ce4d67216bcefb3a854f4002312bdce61a381efc47e4bd4a67467d594

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page