def _unpack_sparse(obj):
    """Unpack the sparse matrix into a format that we can easily iterate over for insertion into a CoreML model."""
    if not _HAS_SCIPY and not sp.sparse.issparse(obj):
        raise TypeError("Object {} is not a scipy sparse matrix type".format(type(obj)))
    return obj.toarray()
Unpack the sparse matrix into a format that we can easily iterate over for insertion into a CoreML model.
coremltools/converters/sklearn/_k_neighbors_classifier.py