标签编码n维分类值

问题描述 投票:0回答:1

我遇到了这篇文章Label encoding across multiple columns in scikit-learn,其中一条评论https://stackoverflow.com/a/30267328/10058906解释了给定列的每个值如何从0到(n-1)的范围内编码,其中n是列的长度。它提出了一个问题,当我编码red: 2orange: 1green: 0这是否暗示绿色更接近橙色而不是红色,因为0接近1比2;这实际上不是真的吗?我之前想过,也许自从green发生了最大次数,它得到了值0。但是,这不适用于fruit列,即使apple gets value 0 orange occurs the maximum number of times

python encoding encode categorical-data
1个回答
0
投票

我想总结Label Encoder和One Hot Encoding:

确实,Label Encoder只是给单元格值一个整数表示。这意味着对于上述数据集,如果我们标记编码我们的分类值 - 它将imply that green is closer to orange than red since 0 is closer to 1 than 2 - 这是错误的。

另一方面,One Hot Encoding为每个分类值创建单独的列,并且给出0或1的值,分别表示该特征的不存在或存在。此外,pd.get_dummies(dataframe)的内置函数产生相同的输出。

因此,如果给定的数据集包含有序数的分类值,那么使用Label Encoding是明智的。但如果给定的数据是名义上的,那么应该继续使用One Hot Encoding

https://discuss.analyticsvidhya.com/t/dummy-variables-is-necessary-to-standardize-them/66867/2

© www.soinside.com 2019 - 2024. All rights reserved.