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 版本兼容性
平台兼容性
Windows macOS Linux类别
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.0.0 |