mpu.ml¶
Machine Learning functions.
-
mpu.ml.
indices2one_hot
(indices, nb_classes)[source]¶ Convert an iterable of indices to one-hot encoded list.
You might also be interested in sklearn.preprocessing.OneHotEncoder
- Parameters
indices (iterable) – iterable of indices
nb_classes (int) – Number of classes
dtype (type) –
- Returns
one_hot
- Return type
list
Examples
>>> indices2one_hot([0, 1, 1], 3) [[1, 0, 0], [0, 1, 0], [0, 1, 0]] >>> indices2one_hot([0, 1, 1], 2) [[1, 0], [0, 1], [0, 1]]
-
mpu.ml.
one_hot2indices
(one_hots)[source]¶ Convert an iterable of one-hot encoded targets to a list of indices.
- Parameters
one_hot (list) –
- Returns
indices
- Return type
list
Examples
>>> one_hot2indices([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) [0, 1, 2]
>>> one_hot2indices([[1, 0], [1, 0], [0, 1]]) [0, 0, 1]