How to drop a column when using the "onehotencode" function?

I am using the "onehotencode" function to create dummy variables for my categorical data. To avoid creating colinear features, in the case of a normal categorical array, I want to drop the last (or first) created logical vector. This is the same as the "Dummy Variables with Reference Group" categorical encoding method detailed in the Statistics and Machine Learning Toolbox documentation page: https://uk.mathworks.com/help/releases/R2023a/stats/dummy-indicator-variables.html .
Is there a function or an input argument for "onehotencode" in MATLAB I can use to drop a column directly?

 Accepted Answer

The ability to drop a column when using "onehotencode" is not available directly in MATLAB.
However, to work around this, remove a column from the encoded label after it has been generated. For example:
A = categorical(["A", "B", "C"])
B = onehotencode(A, 1)
B = B(:, 2:end) % Remove the first column

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!