onehotencode
Encode data labels into one-hot vectors
Syntax
Description
encodes data labels in categorical array B = onehotencode(A,featureDim)A into a one-hot encoded array
B. The function replaces each element of A with a
numeric vector of length equal to the number of unique classes in A along
the dimension specified by featureDim. The vector contains a
1 in the position corresponding to the class of the label in
A, and a 0 in every other position. Any
<undefined> values are encoded to NaN values.
encodes categorical data labels in table tblB = onehotencode(tblA)tblA into a table of one-hot
encoded numeric values. The function replaces the single variable of tblA
with as many variables as the number of unique classes in tblA. Each row in
tblB contains a 1 in the variable corresponding to
the class of the label in tlbA, and a 0 in all other
variables.
___ = onehotencode(___, encodes the labels into numeric values of data type typename)typename. Use this syntax with any of the input and output arguments in previous syntaxes.
___ = onehotencode(___,'ClassNames',
also specifies the names of the classes to use for encoding. Use this syntax when
classes)A or tblA does not contain categorical values,
when you want to exclude any class labels from being encoded, or when you want to encode the
vector elements in a specific order. Any label in A or
tblA of a class that does not exist in classes is
encoded to a vector of NaN values.
Examples
Input Arguments
Output Arguments
Version History
Introduced in R2020b