Skip to main content

Low Rank Matrix Learning Library. A python library for low rank matrix methods used in machine learning, like Matrix Completion, Robust PCA, and CUR factorizations

Project description


Using Matrix Completion for Movie Recomendations

Start by loading the MovieLens1M dataset

data = np.loadtxt( 'ml-1m/ratings.dat',delimiter='::' )
X=data[:, [0,1]].astype(int)-1


(6040, 3952)

So, we have 6040 users and 3952 movies. That's a total of about 23 million potential ratings, of which we know 1 million. We're going to reserve 200,000 of the ratings to test our results.

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

Import, fit the data and make predictions

from MC import *
from statistics import mean

mc_model=MC(n_users,n_movies,5), y_train)


print("Percent of predictions off my less than 1: ",np.sum(abs(y_test-y_predict)<1)/len(y_test))
MAE: 0.6910439339771605
Percent of predictions off my less than 1:  0.7603603243318903

Using Robust Principle Component Analysis for Background Forground Seperation

Import packages, open the video file, and flatten the frames into vectors.

import sys
from LRMatLearnLib.datasets.data_loader import *
from LRMatLearnLib.RPCA.algorithms import *
import matplotlib.pyplot as plt
import matplotlib.animation as animation

v=v.reshape(n_frames, d1*d2)

run altProjNiave, a basic RPCA algorithm. The first arguement is the matrix to be decomposed, the second is the rank of the low rank matrix, and the third is the number of entries in the sparse matrix.

(L,S)=altProjNiave(v, 2,100*n_frames)

Reshape the frames back into images and plot them.

all=np.concatenate((v,L,S), axis=2)



Project details

Release history Release notifications | RSS feed

This version


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

LRMatLearnLib-0.1-py3-none-any.whl (2.3 kB view hashes)

Uploaded py3

Supported by

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