Noise generators¶
The noise generators create controlled label corruption for tabular classification experiments.
Functional API¶
Uniform Randomized Label Flip noise.
Randomly changes a given percentage of labels to another class, using a uniform random selection process.
This function implements class-independent label noise. First, it randomly selects a number of instances according to the global noise level. Then, for each selected instance, it assigns a new label chosen uniformly from the set of available classes. If the new label is equal to the original one, it is shifted to a different class to ensure that the selected instance is actually modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
array - like
|
Original labels. It can be a list, tuple, NumPy array, or any array-like structure containing the class labels. |
required |
noise_level
|
float
|
Global proportion of labels to modify. It must usually be a value between 0 and 1. For example, noise_level=0.1 means that approximately 10% of the labels will be selected for modification. |
0.1
|
random_state
|
int
|
Seed used to initialize the random number generator. It allows the noise generation process to be reproducible. |
42
|
return_mask
|
bool
|
If True, also return a boolean mask indicating which final labels differ from the original labels. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
y_out |
ndarray
|
Copy of the original labels with uniform randomized label flip noise applied. |
noise_mask |
(ndarray, optional)
|
Boolean mask returned only when return_mask=True. |
Notes
This function applies a global noise level, so every instance has the same probability of being selected independently of its original class. Therefore, this corresponds to class-independent noise, not class-dependent noise.
The number of modified labels is computed as:
k = int(noise_level * n)
where n is the total number of instances.
Be aware that indices are selected with replacement because rng.integers is used. Therefore, the final number of different modified positions can be lower than k if the same index is selected more than once.
Examples:
Not At Random label noise.
Applies class-dependent label noise. Each class has its own probability of being shifted to a different randomly selected class.
If noise_levels is provided, the function uses the probability assigned to each class. If noise_levels is None, each class receives a random noise probability sampled uniformly from random_range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
array - like
|
Original labels. It can be a list, tuple, NumPy array, or any array-like structure containing the class labels. |
required |
noise_levels
|
dict
|
Dictionary assigning one noise probability to each class. The keys must be exactly the classes present in y, and the values must be probabilities between 0 and 1. Example: If None, the probabilities are generated randomly using random_range. |
None
|
random_state
|
int
|
Seed used to initialize the random number generator. It makes the noise generation process reproducible. |
42
|
random_range
|
tuple(float, float)
|
Range used to randomly generate the class noise probabilities when noise_levels is None. It must satisfy: |
(0.0, 0.2)
|
return_mask
|
bool
|
If True, also return a boolean mask indicating which final labels differ from the original labels. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
y_out |
ndarray
|
Copy of the original labels with Not At Random noise applied. |
noise_mask |
(ndarray, optional)
|
Boolean mask returned only when return_mask=True. |
Notes
This function does not apply the same noise probability to all instances. Instead, the probability of changing a label depends on its original class. Recall however that no bias is preseted when for a class to be shifted to one of all the available ones.
For each class c, the function: 1. Finds all instances whose label is c. 2. Selects each of those instances with probability noise_levels[c]. 3. Replaces each selected label with a random label different from c.
Therefore, this is class-dependent noise, also called Not At Random noise.
Unlike the URLF function, this function does not force an exact global number of noisy instances. The final number of modified labels depends on the random sampling process inside each class.
Examples:
Estimator API¶
Mask support¶
urlf(..., return_mask=True)andnar(..., return_mask=True)return(y_noisy, noise_mask).URLFNoise.fit_resampleandNARNoise.fit_resamplestore the same mask innoise_mask_.- The mask is
Trueonly where the final label differs from the original label.