Create a Sparse Matrix

Given enough modeling building, most Data Scientists run into a sparse matrix. Effectively this is simply when most of the elements are zeros. As you will see in the code below matrix is considered dense when the elements are mainly nonzero.

You may want to build a sparse matrix to build two very important understandings:

  1. learn how to compress the memory footprint of a matrix object
  2. speed up your machine learning routines

Users of SciKit-Learn will know that there is a requirement to store your data matrix to be in-memory and let’s face it storing all those zero values is a real waste.

 

If you are interested, take a look at this video on sparse matrices: