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
456 téléchargements
Mise à jour 30 jan. 2019

Afficher la licence

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.

Citation pour cette source

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. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2018b
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
Catégories
En savoir plus sur Import Data dans Help Center et MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Publié le Notes de version
1.0.0