Skip to main content

Matrix completion in Python

Last update: February 2020.


Python code for a few approaches at low-dimensional matrix completion.

These methods operate in-memory and do not scale beyond size 1000 x 1000 or so.

Installation

pip3 install matrix-completion

Methods

  1. Nuclear norm minimization (very slow) [1]
  2. Singular value thresholding [2]
  3. Alternating least squares [3,4]
  4. Biased alternating least squares [5]

Usage

import numpy as np
from matrix_completion import svt_solve, calc_unobserved_rmse

U = np.random.randn(20, 5)
V = np.random.randn(15, 5)
R = np.random.randn(20, 15) + np.dot(U, V.T)

mask = np.round(np.random.rand(20, 15))
R_hat = svt_solve(R, mask)

print("RMSE:", calc_unobserved_rmse(U, V, R_hat, mask))

Note that here, the mask is a matrix with entries either 1 (indicating observed) or 0 (indicating missing).

See the examples/ directory for more details.

References

[1] Emmanuel Candès and Benjamin Recht. 2012. Exact matrix completion via convex optimization. Commun. ACM 55, 6 (June 2012), 111-119. DOI: https://doi.org/10.1145/2184319.2184343

[2] Jian-Feng Cai, Emmanuel J. Candès, and Zuowei Shen. 2010. A Singular Value Thresholding Algorithm for Matrix Completion. SIAM J. on Optimization 20, 4 (March 2010), 1956-1982. DOI=http://dx.doi.org/10.1137/080738970

[3] Yifan Hu, Yehuda Koren, and Chris Volinsky. 2008. Collaborative Filtering for Implicit Feedback Datasets. In Proceedings of the 2008 Eighth IEEE International Conference on Data Mining (ICDM '08). IEEE Computer Society, Washington, DC, USA, 263-272. DOI=http://dx.doi.org/10.1109/ICDM.2008.22

[4] Ruslan Salakhutdinov and Andriy Mnih. 2007. Probabilistic Matrix Factorization. In Proceedings of the 20th International Conference on Neural Information Processing Systems (NIPS'07), J. C. Platt, D. Koller, Y. Singer, and S. T. Roweis (Eds.). Curran Associates Inc., USA, 1257-1264.

[5] Paterek, Arkadiusz. “Improving regularized singular value decomposition for collaborative filtering.” (2007).

License

This code is available under the Eclipse Public License.

Metadata

Release files for matrix-completion 0.0.2

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

Source distribution (sdist)

Source distribution for matrix-completion 0.0.2
File Size Uploaded
matrix-completion-0.0.2.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for matrix-completion 0.0.2
File Interpreter ABI Platform
matrix_completion-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / matrix-completion-0.0.2.tar.gz

Download URL matrix-completion-0.0.2.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1c4d2d54a9fc80e50d19bf860bcfbc2f5e7e3a2f3044b8955813cd9905306391
BLAKE2b-256 checksum
How to use checksums
be1ac8a2f26421e595972be6d542e6a65ab14fee862d872f0b7f3222284563cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

Release files / matrix_completion-0.0.2-py3-none-any.whl

Download URL matrix_completion-0.0.2-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df7d85a9fa629685aa2bb8bef0ad72904cfd7cb263d2c3ad5e25d3a48546f12a
BLAKE2b-256 checksum
How to use checksums
868f2221aa532c8d6ed4165824ea40f6c938e95ebce64e01f10ef810a0972317
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

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