One Hot Encoding of a Categorical Variable in a Table

An alternative to MATLAB's dummyvar command for creating ONE HOT ENCODING of categorical data in a table
462 Descargas
Actualizado 30 ene 2019

Ver licencia

Code written by Christopher L. Stokely, January 30, 2019
Written in MATLAB R2018B.

Command:
outputTable = createOneHotEncoding(T,tableVariable)

Input variable T needs to be a table and the tableVariable should be
a variable in that table. tableVariable should be a variable that is
categorical but it does not have to be. The code below converts the
variable to categorical if it is not already so. A table will be
returned that is the original input table without tableVariable, but
with new variables representing the one-hot encoded tableVariable.

By one hot encoding, predictor importances can become very useful
when employing machine learning - from a model interpretability stand
-point. Being able to assign an importance to an individual category
can be useful and important in some cases.

For educational purposes, try looking into these Machine Learning
toolbox commands after building a model:
1) oobPermutedPredictorImportance
2) predictorImportance (Be careful - this one is known to mislead)
3) FeatureSelectionNCARRegression
4) fsrnca or fscnca
5) sequentialfs
6) plotPartialDependence
7) Individual Conditional Expectation (ICE) plots

Note a MATLAB bug or oversight from MathWorks regarding having an
underscore in the variable names that are in the table...
Note that the output table has new variables with labels that have an
underscore. Removing these variables with "removevars" requires the
user to specify the column to be removed with the column number, not
the variable name. Otherwise unintended columns will be deleted.

Citar como

Christopher Stokely (2024). One Hot Encoding of a Categorical Variable in a Table (https://www.mathworks.com/matlabcentral/fileexchange/70140-one-hot-encoding-of-a-categorical-variable-in-a-table), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2018b
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre Import Data en Help Center y MATLAB Answers.

Community Treasure Hunt

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

Start Hunting!
Versión Publicado Notas de la versión
1.0.0