Encode data labels into one-hot vectors
encodes data labels in categorical array B
= onehotencode(A
,featureDim
)A
into a one-hot encoded array
B
. Each element of A
is replaced 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 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 single variable of tblA
is replaced 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
.
___ = onehotencode(___,'ClassNames',
also specifies the names of the classes to use for encoding. Use this syntax when
classes
)A
or tblA
do 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.