aggregate
aggregate_mean_var(X, y, sort=False)
¶
Aggregate array to mean.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
ndarray
|
X array, shape |
required |
y |
ndarray
|
values, shape |
required |
sort |
bool
|
Whether to sort the resulting DataFrame by the group keys. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
aggregated |
ndarray
|
aggregated (mean per group) |
ndarray
|
aggregated (variance per group) |
Examples:
>>> from spotpython.utils.aggregate import aggregate_mean_var
X = np.array([[1, 2], [3, 4], [1, 2]])
y = np.array([1, 2, 3])
X_agg, y_mean, y_var = aggregate_mean_var(X, y)
print(X_agg)
[[1. 2.]
[3. 4.]]
print(y_mean)
[2. 2.]
print(y_var)
[1. 0.]
Source code in spotpython/utils/aggregate.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
get_ranks(x)
¶
Returns a numpy array containing ranks of numbers within an input numpy array x.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
ndarray
|
numpy array |
required |
Returns:
Type | Description |
---|---|
ndarray
|
ranks |
Examples:
>>> get_ranks([2, 1])
[1, 0]
>>> get_ranks([20, 10, 100])
[1, 0, 2]
Source code in spotpython/utils/aggregate.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
select_distant_points(X, y, k)
¶
Selects k points that are distant from each other using a clustering approach.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
ndarray
|
X array, shape |
required |
y |
ndarray
|
values, shape |
required |
k |
int
|
number of points to select. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
selected |
ndarray
|
selected |
Examples:
>>> from spotpython.utils.aggregate import select_distant_points
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]])
y = np.array([1, 2, 3, 4, 5])
selected_points, selected_y = select_distant_points(X, y, 3)
print(selected_points)
[[1 2]
[7 8]
[9 10]]
print(selected_y)
[1 4 5]
Source code in spotpython/utils/aggregate.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|