Decay Functions¶
These functions are used in the DecayEstimator
to generate sample weights for the wrapped model.
sklego.meta._decay_utils.exponential_decay(X, y, decay_rate=0.999)
¶
Generates an exponential decay by mapping input data X
, y
to a exponential decreasing range
\(w_{t-1} = decay\_rate * w_{t}\). The length of the decay is determined by the number of samples in y
.
Warning
It is up to the user to sort the dataset appropriately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
array-like, shape=(n_samples, n_features,)
|
Training data. Unused, present for API consistency by convention. |
required |
y
|
array-like, shape=(n_samples,)
|
Target values. Used to determine the number of samples in the decay. |
required |
decay_rate
|
float
|
The rate of decay. |
0.999
|
Returns:
Type | Description |
---|---|
np.ndarray, shape=(n_samples,)
|
The decay values. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in sklego/meta/_decay_utils.py
sklego.meta._decay_utils.linear_decay(X, y, min_value=0.0, max_value=1.0)
¶
Generates a linear decay by mapping input data X
, y
to a linearly decreasing range from max_value
to min_value
. The length and step of the decay is determined by the number of samples in y
.
Warning
It is up to the user to sort the dataset appropriately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
array-like, shape=(n_samples, n_features,)
|
Training data. Unused, present for API consistency by convention. |
required |
y
|
array-like, shape=(n_samples,)
|
Target values. Used to determine the number of samples in the decay. |
required |
min_value
|
float
|
The minimum value of the decay. |
0.
|
max_value
|
float
|
The maximum value of the decay. |
1.
|
Returns:
Type | Description |
---|---|
np.ndarray, shape=(n_samples,)
|
The decay values. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in sklego/meta/_decay_utils.py
sklego.meta._decay_utils.sigmoid_decay(X, y, growth_rate=None, min_value=0.0, max_value=1.0)
¶
Generates a sigmoid decay function that maps input data X
, y
to a non-linearly decreasing range from
max_value
to min_value
. The steepness of the decay is determined by the growth_rate
parameter.
If not provided this will be set to 10 / n_samples
, which is a "good enough" default for most cases.
Warning
It is up to the user to sort the dataset appropriately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
array-like, shape=(n_samples, n_features,)
|
Training data. Unused, present for API consistency by convention. |
required |
y
|
array-like, shape=(n_samples,)
|
Target values. Used to determine the number of samples in the decay. |
required |
growth_rate
|
float | None
|
The growth rate of the sigmoid function. If not provided this will be set to |
None
|
min_value
|
float
|
The minimum value of the decay. |
0.
|
max_value
|
float
|
The maximum value of the decay. |
1.
|
Returns:
Type | Description |
---|---|
np.ndarray, shape=(n_samples,)
|
The decay values. |
Raises:
Type | Description |
---|---|
ValueError
|
|
Source code in sklego/meta/_decay_utils.py
sklego.meta._decay_utils.stepwise_decay(X, y, n_steps=None, step_size=None, min_value=0.0, max_value=1.0)
¶
Generates a stepwise decay function that maps input data X
, y
to a decreasing range from max_value
to
min_value
.
It is possible to specify one of n_steps
or step_size
to determine the behaviour of the decay.
- If
step_size
is provided, the decay will be split inton_samples // step_size
steps, each of which will decrease the value bystep_width = (max_value - min_value) / n_steps
. - If
n_steps
is provided, the decay will be split inton_steps
steps, each of which will decrease the value bystep_width = (max_value - min_value) / n_steps
.
Each step of length step_size has constant weight, and then decreases by step_width
until the minimum value is
reached.
Warning
It is up to the user to sort the dataset appropriately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
array-like, shape=(n_samples, n_features,)
|
Training data. Unused, present for API consistency by convention. |
required |
y
|
array-like, shape=(n_samples,)
|
Target values. Used to determine the number of samples in the decay. |
required |
n_steps
|
int | None
|
The total number of steps in the decay. |
None
|
step_size
|
int | None
|
The number of samples for each step in the decay. |
None
|
min_value
|
float
|
The minimum value of the decay. |
0.
|
max_value
|
float
|
The maximum value of the decay. |
1.
|
Returns:
Type | Description |
---|---|
np.ndarray, shape=(n_samples,)
|
The decay values. |
Raises:
Type | Description |
---|---|
ValueError
|
|
TypeError
|
|
Source code in sklego/meta/_decay_utils.py
73 74 75 76 77 78 79 80 81 82 83 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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|