density
- sklearn.utils.extmath.density(w)
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
Compute density of a sparse vector.
The input data can be numpy ndarray or a sparse matrix.
The density of w, between 0 and 1.
>>> from scipy import sparse
>>> from sklearn.utils.extmath import density
>>> X = sparse.random_array((10, 10), density=0.25, rng=0)
>>> density(X)
0.25
Classification of text documents using sparse features