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.0 次下载
更新时间 2019/1/30

查看许可证

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.

引用格式

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. 检索时间: .

MATLAB 版本兼容性
创建方式 R2018b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Import Data 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0