liana.pp.zi_minmax

Contents

liana.pp.zi_minmax#

liana.pp.zi_minmax(X, cutoff=0.5)#

Zero-inflated min-max scaling, adopted from CiteFuse (Kim et al., 2020; https://academic.oup.com/bioinformatics/article/36/14/4137/5827474).

This function scales the data to the range [0, 1] for each column of a two-dimensional array and sets values below a specified cutoff to 0 (after scaling).

Parameters:
X NDArray[number] | csc_matrix | csr_matrix | csc_array | csr_array

Data to be scaled.

cutoff float (default: 0.5)

Cutoff value for zero-inflation - values less than this are set to 0. Default is 0.5.

Return type:

csr_matrix

Returns:

X The scaled data matrix

Examples

>>> import numpy as np
>>> import liana as li
>>> x = np.array([[0.1, 0.3], [2.0, 4.0], [5.5, 7.1]])
>>> li.pp.zi_minmax(x).toarray().round(3)
array([[0.   , 0.   ],
       [0.   , 0.544],
       [1.   , 1.   ]])

cutoff is applied after scaling, so lowering it keeps more of the middle:

>>> li.pp.zi_minmax(x, cutoff=0.1).toarray().round(3)
array([[0.   , 0.   ],
       [0.352, 0.544],
       [1.   , 1.   ]])