Label Transforms
transforms.Select
- class torcheeg.transforms.Select(key: Union[str, List])[source]
Select part of the value from the information dictionary.
transform = Select(key='valence') transform(y={'valence': 4.5, 'arousal': 5.5, 'subject_id': 7})['y'] >>> 4.5
Select
allows multiple values to be selected and returned as a list. Suitable for multi-classification tasks or multi-task learning.transform = Select(key=['valence', 'arousal']) transform(y={'valence': 4.5, 'arousal': 5.5, 'subject_id': 7})['y'] >>> [4.5, 5.5]
- Parameters
key (str or list) – The selected key can be a key string or a list of keys.
transforms.FixCategory
- class torcheeg.transforms.FixCategory(value: Union[int, str, List])[source]
Returns a pre-set label for all samples, usually used to supplement the dataset with new categories.
transform = FixCategory(value=0) transform(y=3)['y'] >>> 0
FixCategory
allows multiple values to be selected and returned as a list. Suitable for multi-classification tasks or multi-task learning.transform = FixCategory(value=[0, 1]) transform(y=[1, 2])['y'] >>> [0, 1]
- Parameters
value (str or list) – The pre-set label.
transforms.Binary
- class torcheeg.transforms.Binary(threshold: float)[source]
Binarize the label according to a certain threshold. Labels larger than the threshold are set to 1, and labels smaller than the threshold are set to 0.
transform = Binary(threshold=5.0) transform(y=4.5)['y'] >>> 0
Binary
allows simultaneous binarization using the same threshold for multiple labels.transform = Binary(threshold=5.0) transform(y=[4.5, 5.5])['y'] >>> [0, 1]
- Parameters
threshold (float) – Threshold used during binarization.
transforms.BinaryOneVSRest
- class torcheeg.transforms.BinaryOneVSRest(positive: int)[source]
Binarize the label following the fashion of the one-vs-rest strategy. When label is the specified positive category label, the label is set to 1, when the label is any other category label, the label is set to 0.
transform = BinaryOneVSRest(positive=1) transform(y=2)['y'] >>> 0
Binary
allows simultaneous binarization using the same threshold for multiple labels.transform = BinaryOneVSRest(positive=1) transform(y=[1, 2])['y'] >>> [1, 0]
- Parameters
positive (int) – The specified positive category label.
- __call__(*args, **kwargs) Dict[str, any]
Call self as a function.
transforms.BinariesToCategory
- class torcheeg.transforms.BinariesToCategory[source]
Convert multiple binary labels into one multiclass label. Multiclass labels represent permutations of binary labels. Commonly used to combine two binary classification tasks into a single quad classification task.
transform = BinariesToCategory() transform(y=[0, 0])['y'] >>> 0 transform(y=[0, 1])['y'] >>> 1 transform(y=[1, 0])['y'] >>> 2 transform(y=[1, 1])['y'] >>> 3
transforms.StringToInt
- class torcheeg.transforms.StringToInt[source]
Identify numbers in strings and convert strings to numbers. If there is no number in the string, the output corresponding to the string is 0.
transform = StringToInt() transform(y='None')['y'] >>> 0 transform = StringToInt() transform(y='sub001')['y'] >>> 1
StringToInt
allows converting a list of strings to a list of numbers with the same conversion behavior as a single string.transform = StringToInt() transform(y=['sub001', '4'])['y'] >>> 1, 4