sklearn.utils.extmath.density

sklearn.utils.extmath.density(w)[source]

Compute density of a sparse vector.

Parameters:
w{ndarray, sparse matrix}

The input data can be numpy ndarray or a sparse matrix.

Returns:
float

The density of w, between 0 and 1.

Examples

>>> from scipy import sparse
>>> from sklearn.utils.extmath import density
>>> X = sparse.random(10, 10, density=0.25, random_state=0)
>>> density(X)
0.25

Examples using sklearn.utils.extmath.density

Classification of text documents using sparse features

Classification of text documents using sparse features