-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_ml100k.py
More file actions
23 lines (20 loc) · 761 Bytes
/
load_ml100k.py
File metadata and controls
23 lines (20 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# This code is supporting material for the book
# Building Machine Learning Systems with Python
# by Willi Richert and Luis Pedro Coelho
# published by PACKT Publishing
#
# It is made available under the MIT License
def load():
'''Load ML-100k data
Returns the review matrix as a numpy array'''
import numpy as np
from scipy import sparse
# The input is in the form of a CSC sparse matrix, so it's a natural fit to
# load the data, but we then convert to a more traditional array before
# returning
data = np.loadtxt('data/ml-100k/u.data')
ij = data[:, :2]
ij -= 1 # original data is in 1-based system
values = data[:, 2]
reviews = sparse.csc_matrix((values, ij.T)).astype(float)
return reviews.toarray()