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

LRMatLearnLib

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
y=data[:,2]

n_users=max(X[:,0])+1
n_movies=max(X[:,1])+1

print((n_users,n_movies))
(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 MC.py, fit the data and make predictions

from MC import *
from statistics import mean

mc_model=MC(n_users,n_movies,5)
mc_model.fit(np.array(X_train).transpose(), y_train)
y_predict=mc_model.predict((np.array(X_test).transpose()))

print("MAE:",mean(abs(y_test-y_predict)))

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
sys.path.append('../')
from LRMatLearnLib.datasets.data_loader import *
from LRMatLearnLib.RPCA.algorithms import *
import matplotlib.pyplot as plt
import matplotlib.animation as animation

v=load_video("../datasets/videos/escalator.avi")
(n_frames,d1,d2)=v.shape
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.

L=L.reshape(n_frames,d1,d2)
S=S.reshape(n_frames,d1,d2)
v=v.reshape(n_frames,d1,d2)
all=np.concatenate((v,L,S), axis=2)

plt.imshow(all[1,:,:])
plt.show()

png

Project details


Release history Release notifications | RSS feed

This version

0.1

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 details)

Uploaded Python 3

File details

Details for the file LRMatLearnLib-0.1-py3-none-any.whl.

File metadata

  • Download URL: LRMatLearnLib-0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.9

File hashes

Hashes for LRMatLearnLib-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 43dba580d708b336e383cf5d5501530217354db09e2e96c38c56c9d7d23d11ab
MD5 bc759c1fd382123a0924509b615a4934
BLAKE2b-256 ade161af6574300b22698f42594c91c5dc9b583fe36d4973bb919b3eaea49cd6

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