I have a csv file in this format:
userId movieId rating timestamp
1 31 2.5 1260759144
2 10 4 835355493
3 1197 5 1298932770
4 10 4 949810645
I want to build a sparse matrix with rows as userId and columns as movieID. I saved all the data as a dictionary with the name "column", where the ['user'] column contains user identifiers, the ['movie'] column has movie identifiers, and the ['ratings'] column has ratings as follows:
f = open('ratings.csv','rb')
reader = csv.reader(f)
headers = ['user','movie','rating','timestamp']
column = {}
for h in headers:
column[h] = []
for row in reader:
for h, v in zip(headers, row):
column[h].append(float(v))
When I call a sparse matrix function as follows:
mat = scipy.sparse.csr_matrix((column['rating'],(column['user'],column['movie'])))
I get "TypeError: invalid form"
Please, help
Alice source
share