Documentation for Labelflipping Module¶
This module provides classes for label flipping attacks in datasets, allowing for the simulation of label noise as a form of data poisoning. It implements both targeted and non-targeted label flipping attacks.
Classes: - LabelFlippingAttack: Main attack class that implements the DatasetAttack interface - LabelFlippingStrategy: Abstract base class for label flipping strategies - TargetedLabelFlippingStrategy: Implementation for targeted label flipping - NonTargetedLabelFlippingStrategy: Implementation for non-targeted label flipping
LabelFlippingAttack
¶
Bases: DatasetAttack
Implements a label flipping attack that can be either targeted or non-targeted.
Source code in nebula/addons/attacks/dataset/labelflipping.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
__init__(engine, attack_params)
¶
Initialize the label flipping attack.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
engine
|
The engine managing the attack context |
required | |
attack_params
|
Dict
|
Dictionary containing attack parameters |
required |
Source code in nebula/addons/attacks/dataset/labelflipping.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
get_malicious_dataset()
¶
Creates a malicious dataset by flipping the labels of selected data points.
Returns:
Name | Type | Description |
---|---|---|
Dataset |
The modified dataset with flipped labels |
Source code in nebula/addons/attacks/dataset/labelflipping.py
182 183 184 185 186 187 188 189 190 191 192 193 |
|
LabelFlippingStrategy
¶
Bases: ABC
Abstract base class for label flipping strategies.
Source code in nebula/addons/attacks/dataset/labelflipping.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
flip_labels(dataset, indices, poisoned_percent)
abstractmethod
¶
Abstract method to flip labels in the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset
|
The dataset to modify |
required | |
indices
|
list[int]
|
List of indices to consider for flipping |
required |
poisoned_percent
|
float
|
Percentage of labels to change (0-100) |
required |
Returns:
Type | Description |
---|---|
Dataset
|
Modified dataset with flipped labels |
Source code in nebula/addons/attacks/dataset/labelflipping.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
NonTargetedLabelFlippingStrategy
¶
Bases: LabelFlippingStrategy
Implementation of non-targeted label flipping strategy.
Source code in nebula/addons/attacks/dataset/labelflipping.py
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 |
|
flip_labels(dataset, indices, poisoned_percent)
¶
Flips labels randomly to different classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset
|
The dataset to modify |
required | |
indices
|
list[int]
|
List of indices to consider for flipping |
required |
poisoned_percent
|
float
|
Percentage of labels to change (0-100) |
required |
Returns:
Type | Description |
---|---|
Dataset
|
Modified dataset with flipped labels |
Source code in nebula/addons/attacks/dataset/labelflipping.py
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 |
|
TargetedLabelFlippingStrategy
¶
Bases: LabelFlippingStrategy
Implementation of targeted label flipping strategy.
Source code in nebula/addons/attacks/dataset/labelflipping.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 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 |
|
__init__(target_label, target_changed_label)
¶
Initialize targeted label flipping strategy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_label
|
int
|
The label to change |
required |
target_changed_label
|
int
|
The label to change to |
required |
Source code in nebula/addons/attacks/dataset/labelflipping.py
53 54 55 56 57 58 59 60 61 62 |
|
flip_labels(dataset, indices, poisoned_percent)
¶
Flips labels from target_label to target_changed_label.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset
|
The dataset to modify |
required | |
indices
|
list[int]
|
List of indices to consider for flipping |
required |
poisoned_percent
|
float
|
Percentage of labels to change (0-100) |
required |
Returns:
Type | Description |
---|---|
Dataset
|
Modified dataset with flipped labels |
Source code in nebula/addons/attacks/dataset/labelflipping.py
64 65 66 67 68 69 70 71 72 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 |
|