当前位置:网站首页>什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
2022-07-03 14:53:00 【Hali_Botebie】
什么是Label encoding
label encoding 就是用标签进行编码的意思,即将原始特征值编码为自定义的数字标签完成量化编码过程。
举例:
假如有三种颜色特征:红、黄、蓝。 在利用机器学习的算法时一般需要进行向量化或者数字化。那么你可能想令 红=1,黄=2,蓝=3. 那么这样其实实现了标签编码,即给不同类别以标签。
特点
- 优点:解决了分类编码的问题,可以自由定义量化数字。但其实也是缺点,因为数值本身没有任何含义,只是排序。如大中小编码为123,也可以编码为321,即数值没有意义。
- 缺点:可解释性比较差。比如有[dog,cat,dog,mouse,cat],我们把其转换为[1,2,1,3,2],这里就产生了一个奇怪的现象:dog和mouse的平均值是cat。因此,Label encoding编码其实并没有很宽的应用场景。
one-hot encoding ,label encoding两种编码该如何区分和使用?
1.特征数据类型
对于定类类型的数据,建议使用one-hot encoding。 定类类型就是纯分类,不排序,没有逻辑关系。比如性别分男和女,男女不存在任何逻辑关系,我们不能说男就比女好,或者相反。再者,中国各省市分类也可以用独热编码,同样各省不存在逻辑关系,这时候使用one-hot encoding会合适些。但注意,一般会舍去一个变量,比如男的对立面肯定是女,那么女就是重复信息,所以保留其中一个变量即可。
对于定序类型的数据,建议使用label encoding。 定序类型也是分类,但有排序逻辑关系,等级上高于定类。比如,学历分小学,初中,高中,本科,研究生,各个类别之间存在一定的逻辑,显然研究生学历是最高的,小学最低。这时候使用Label encoding会显得更合适,因为自定义的数字顺序可以不破坏原有逻辑,并与这个逻辑相对应。
2.所使用的模型
对数值大小敏感的模型必须使用one-hotencoding。 典型的例子就是LR和SVM。二者的损失函数对数值大小是敏感的,并且变量间的数值大小是有比较意义的。而Label encoding的数字编码没有数值大小的含义,只是一种排序,因此对于这些模型都使用one-hot encoding。
对数值大小不敏感的模型(如树模型)不建议使用one-hotencoding。 一般这类模型为树模型。如果分类类别特别多,那么one-hot encoding会分裂出很多特征变量。这时候,如果我们限制了树模型的深度而不能向下分裂的话,一些特征变量可能就因为模型无法继续分裂而被舍弃损失掉了。因此,此种情况下可以考虑使用Label encoding。
以上两点考量需要综合考虑,而非单独判断。也就是说需要结合数据类型和模型的情况来具体选择编码方式。
————————————————
版权声明:本文为CSDN博主「素笺清风」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_45834085/article/details/102991983
边栏推荐
- Global and Chinese market of postal automation systems 2022-2028: Research Report on technology, participants, trends, market size and share
- NOI OPENJUDGE 1.5(23)
- C string format (decimal point retention / decimal conversion, etc.)
- Yolov5进阶之八 高低版本格式转换问题
- Some concepts about agile
- [ue4] HISM large scale vegetation rendering solution
- Zzuli:1048 factorial table
- [engine development] rendering architecture and advanced graphics programming
- [ue4] geometry drawing pipeline
- Plane vector addition
猜你喜欢
![[wechat applet] wxss template style](/img/28/f9d12bf761e25f9564d92697cf049d.png)
[wechat applet] wxss template style

5.2-5.3

4-24--4-28

CentOS7部署哨兵Redis(带架构图,清晰易懂)

Byte practice plane longitude 2

Adc128s022 ADC Verilog design and Implementation

QT - draw something else

Troubleshooting method of CPU surge
![[ue4] Niagara's indirect draw](/img/8a/576022b5d19e1d6422ff0135c50c93.jpg)
[ue4] Niagara's indirect draw

C string format (decimal point retention / decimal conversion, etc.)
随机推荐
556. 下一个更大元素 III : 简单构造模拟题
tonybot 人形機器人 紅外遙控玩法 0630
B2020 分糖果
1017 a divided by B (20 points)
Déformation de la chaîne bm83 de niuke (conversion de cas, inversion de chaîne, remplacement de chaîne)
5.2-5.3
[engine development] rendering architecture and advanced graphics programming
Find books ()
C language fcntl function
从书本《皮囊》摘录的几个句子
Pyqt interface production (login + jump page)
There are links in the linked list. Can you walk three steps faster or slower
Zzuli:1049 square sum and cubic sum
Class part2
Global and Chinese market of optical fiber connectors 2022-2028: Research Report on technology, participants, trends, market size and share
Yolov5 advanced nine target tracking example 1
2021-10-16 initial programming
Joomla! CMS 3.0~3.4.6 RCE
Detailed explanation of four modes of distributed transaction (Seata)
Zhejiang University Edition "C language programming (4th Edition)" topic set reference ideas set