- Learning Data Mining with Python(Second Edition)
- Robert Layton
- 304字
- 2021-07-02 23:40:12
Sparse data formats
This dataset is in a sparse format. Each row can be thought of as a cell in a large feature matrix of the type used in previous chapters, where rows are users and columns are inpidual movies. The first column would be each user's review of the first movie, the second column would be each user's review of the second movie, and so on.
There are around 1,000 users and 1,700 movies in this dataset, which means that the full matrix would be quite large (nearly 2 million entries). We may run into issues storing the whole matrix in memory and computing on it would be troublesome. However, this matrix has the property that most cells are empty, that is, there is no review for most movies for most users. There is no review of movie number 675 for user number 213 though, and not for most other combinations of user and movie.
The format given here represents the full matrix, but in a more compact way. The first row indicates that user number 196 reviewed movie number 242, giving it a ranking of 3 (out of five) on December 4, 1997.
Any combination of user and movie that isn't in this database is assumed to not exist. This saves significant space, as opposed to storing a bunch of zeroes in memory. This type of format is called a sparse matrix format. As a rule of thumb, if you expect about 60 percent or more of your dataset to be empty or zero, a sparse format will take less space to store.
When computing on sparse matrices, the focus isn't usually on the data we don't have—comparing all of the zeroes. We usually focus on the data we have and compare those.