-
Notifications
You must be signed in to change notification settings - Fork 3
/
loader.py
43 lines (35 loc) · 1001 Bytes
/
loader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
'''
@author alle.veenstra@gmail.com
'''
import math
import itertools
import numpy
import matplotlib
import csv
import string
from scipy.sparse import lil_matrix
class MovieLoader(object):
def getM(self):
return 943
def getN(self):
return 1682
def loadMovies(self):
X = lil_matrix((943, 1682))
filename = "ml-data/u.data"
reader = csv.reader(open(filename, 'rb'), delimiter = '\t', quotechar = '|')
for row in reader:
user = string.atoi(row[0]) - 1
movie = string.atoi(row[1]) - 1
rating = string.atoi(row[2])
X[user, movie] = rating
return X
def loadTitles(self):
X = {}
filename = "ml-data/u.item"
reader = csv.reader(open(filename, 'rb'), delimiter = '|', quotechar = '|')
for row in reader:
id = string.atoi(row[0]) - 1
movie = row[1]
X[id] = movie
return X