|
5 | 5 |
|
6 | 6 | def zi_minmax(X: ArrayLike, cutoff: float = 0.5) -> csr_matrix: |
7 | 7 | """ |
8 | | - Zero-inflated min-max scaling, adopted from CiteFuse (Kim et al., 2020; https://academic.oup.com/bioinformatics/article/36/14/4137/5827474). |
| 8 | + Zero-inflated min-max scaling, adopted from CiteFuse (Kim et al., 2020; |
| 9 | + https://academic.oup.com/bioinformatics/article/36/14/4137/5827474). |
9 | 10 |
|
10 | | - This function scales the data to the range [0, 1] and sets values below a specified cutoff to 0. |
| 11 | + This function scales the data to the range [0, 1] for each column of a |
| 12 | + two-dimensional array and sets values below a specified cutoff to 0 (after |
| 13 | + scaling). |
11 | 14 |
|
12 | 15 | Parameters |
13 | 16 | ---------- |
14 | 17 | X |
15 | 18 | Data to be scaled. |
16 | 19 | cutoff |
17 | | - Cutoff value for zero-inflation - values less than this are set to 0. Default is 0.5. |
| 20 | + Cutoff value for zero-inflation - values less than this are set to 0. |
| 21 | + Default is 0.5. |
18 | 22 |
|
19 | 23 | Returns |
20 | 24 | ------- |
21 | 25 | X |
22 | 26 | The scaled data matrix |
23 | 27 |
|
| 28 | + Examples |
| 29 | + -------- |
| 30 | + >>> x = np.array([[0.1, 0.3], |
| 31 | + ... [2.0, 4.0], |
| 32 | + ... [5.5, 7.1]]) |
| 33 | + >>> print(zi_minmax(x)) |
| 34 | + <Compressed Sparse Row sparse matrix of dtype 'float64' |
| 35 | + with 6 stored elements and shape (3, 2)> |
| 36 | + Coords Values |
| 37 | + (0, 0) 0.0 |
| 38 | + (0, 1) 0.0 |
| 39 | + (1, 0) 0.0 |
| 40 | + (1, 1) 0.5441176470588236 |
| 41 | + (2, 0) 1.0 |
| 42 | + (2, 1) 1.0 |
| 43 | + >>> print(zi_minmax(x, cutoff=0.1)) |
| 44 | + <Compressed Sparse Row sparse matrix of dtype 'float64' |
| 45 | + with 6 stored elements and shape (3, 2)> |
| 46 | + Coords Values |
| 47 | + (0, 0) 0.0 |
| 48 | + (0, 1) 0.0 |
| 49 | + (1, 0) 0.3518518518518518 |
| 50 | + (1, 1) 0.5441176470588236 |
| 51 | + (2, 0) 1.0 |
| 52 | + (2, 1) 1.0 |
| 53 | +
|
24 | 54 | """ |
25 | 55 | X = X.copy() |
26 | 56 | if not isspmatrix_csr(X): |
@@ -59,6 +89,27 @@ def neg_to_zero(X: ArrayLike, cutoff: float = 0) -> csr_matrix: |
59 | 89 | ------- |
60 | 90 | The modified data matrix |
61 | 91 |
|
| 92 | + Examples |
| 93 | + -------- |
| 94 | + >>> x = np.array([-1, -0.5, 0.1, 0.4, 2]) |
| 95 | + >>> print(neg_to_zero(x)) |
| 96 | + <Compressed Sparse Row sparse matrix of dtype 'float64' |
| 97 | + with 5 stored elements and shape (1, 5)> |
| 98 | + Coords Values |
| 99 | + (0, 0) 0.0 |
| 100 | + (0, 1) 0.0 |
| 101 | + (0, 2) 0.1 |
| 102 | + (0, 3) 0.4 |
| 103 | + (0, 4) 2.0 |
| 104 | + >>> print(neg_to_zero(x, cutoff=0.5)) |
| 105 | + <Compressed Sparse Row sparse matrix of dtype 'float64' |
| 106 | + with 5 stored elements and shape (1, 5)> |
| 107 | + Coords Values |
| 108 | + (0, 0) 0.0 |
| 109 | + (0, 1) 0.0 |
| 110 | + (0, 2) 0.0 |
| 111 | + (0, 3) 0.0 |
| 112 | + (0, 4) 2.0 |
62 | 113 | """ |
63 | 114 | X = X.copy() |
64 | 115 | if not isspmatrix_csr(X): |
|
0 commit comments