Categorical To OneHot
Description
Converts categories into one-hot encoded vectors for machine learning. Type : polymorphic.
Documentation illustration (illustration unavailable in the archive).
Input parameters
label : array, an array or tensor of integer indices representing the class of each sample. If label has dimension n, the output will have dimension n+1 because a new axis is added for the one‑hot representation.
nb_classes : integer, total number of classes. Defines the size of the new axis added for the one‑hot encoding (example : if nb_classes = 5, the new axis will have size 5).
axis : integer, position at which to insert the new axis in the tensor. The value of axis must be between 0 and n (where n is the rank of label).
-
axis = n→ adds the new dimension at the end.axis = 0→ adds the new dimension at the beginning.
Output parameters
one_hot : array, the resulting one‑hot tensor, obtained by inserting an axis of size nb_classes at the specified axis position. Each index in label is converted to a one‑hot vector of length nb_classes.
Use cases
The one-hot transformation function is used to convert categorical data (such as class names or types) into binary vectors. Each category is represented by a vector containing a single “1” and “0”s elsewhere. This representation allows machine learning and deep learning algorithms to properly handle non-numeric data without introducing any ordinal relationship between categories.
Example
All these exemples are snippets PNG, you can drop these Snippet onto the block diagram and get the depicted code added to your VI (Do not forget to install Deep Learning library to run it).
