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()
Release files for LRMatLearnLib 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| LRMatLearnLib-0.1-py3-none-any.whl | Python 3 | none | any | Details |
Release files / LRMatLearnLib-0.1-py3-none-any.whl
| Download URL | LRMatLearnLib-0.1-py3-none-any.whl |
|---|---|
| Size | 2.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
43dba580d708b336e383cf5d5501530217354db09e2e96c38c56c9d7d23d11ab
|
|
BLAKE2b-256 checksum How to use checksums |
ade161af6574300b22698f42594c91c5dc9b583fe36d4973bb919b3eaea49cd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|