Feature Engineering 特征工程 2. Categorical Encodings

文章目录

    • 1. Count Encoding 计数编码
    • 2. Target Encoding 目标编码
    • 3. CatBoost Encoding

learn from https://www.kaggle.com/learn/feature-engineering

上一篇:Feature Engineering 特征工程 1. Baseline Model

下一篇:Feature Engineering 特征工程 3. Feature Generation


在中级机器学习里介绍过了Label EncodingOne-Hot Encoding,下面将学习count encoding计数编码,target encoding目标编码、singular value decomposition奇异值分解

在上一篇中使用LabelEncoder(),得分为Validation AUC score: 0.7467

# Label encoding
cat_features = ['category', 'currency', 'country']
encoder = LabelEncoder()
encoded = ks[cat_features].apply(encoder.fit_transform)

1. Count Encoding 计数编码

  • 计数编码,就是把该类型的value,替换为其出现的次数
    例如:一个特征中CN出现了100次,那么就将CN,替换成数值100

  • category_encoders.CountEncoder(),最终得分Validation AUC score: 0.7486

import category_encoders as ce
cat_features = ['category', 'currency', 'country']
count_enc = ce.CountEncoder()
count_encoded = count_enc.fit_transform(ks[cat_features])data = baseline_data.join(count_encoded.add_suffix("_count"))# Training a model on the baseline data
train, valid, test = get_data_splits(data)
bst = train_model(train, valid)

2. Target Encoding 目标编码

  • category_encoders.TargetEncoder(),最终得分Validation AUC score: 0.7491

Target encoding replaces a categorical value with the average value of the target for that value of the feature.
目标编码:将会用该特征值的 label 的平均值 替换 分类特征值
For example, given the country value “CA”, you’d calculate the average outcome for all the rows with country == ‘CA’, around 0.28.
举例子:特征值 “CA”,你要计算所有 “CA” 行的 label(即outcome列)的均值,用该均值来替换 “CA”
This is often blended with the target probability over the entire dataset to reduce the variance of values with few occurences.
这么做,可以降低很少出现的值的方差?


This technique uses the targets to create new features. So including the validation or test data in the target encodings would be a form of target leakage.
这种编码方法会产生新的特征,不要把验证集和测试集拿进来fit,会产生数据泄露
Instead, you should learn the target encodings from the training dataset only and apply it to the other datasets.
应该从训练集里fit,应用到其他数据集

import category_encoders as ce
cat_features = ['category', 'currency', 'country']# Create the encoder itself
target_enc = ce.TargetEncoder(cols=cat_features)train, valid, _ = get_data_splits(data)# Fit the encoder using the categorical features and target
target_enc.fit(train[cat_features], train['outcome'])# Transform the features, rename the columns with _target suffix, and join to dataframe
train = train.join(target_enc.transform(train[cat_features]).add_suffix('_target'))
valid = valid.join(target_enc.transform(valid[cat_features]).add_suffix('_target'))train.head()
bst = train_model(train, valid)

3. CatBoost Encoding

  • category_encoders.CatBoostEncoder(),最终得分Validation AUC score: 0.7492

This is similar to target encoding in that it’s based on the target probablity for a given value.
跟目标编码类似的点在于,它基于给定值的 label 目标概率
However with CatBoost, for each row, the target probability is calculated only from the rows before it.
计算上,对每一行,目标概率的计算只依靠它之前的行

cat_features = ['category', 'currency', 'country']
target_enc = ce.CatBoostEncoder(cols=cat_features)train, valid, _ = get_data_splits(data)
target_enc.fit(train[cat_features], train['outcome'])train = train.join(target_enc.transform(train[cat_features]).add_suffix('_cb'))
valid = valid.join(target_enc.transform(valid[cat_features]).add_suffix('_cb'))bst = train_model(train, valid)

上一篇:Feature Engineering 特征工程 1. Baseline Model

下一篇:Feature Engineering 特征工程 3. Feature Generation

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/475779.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于Silverlight+WCF的SAAS开发平台TAP(二)之核心技术

1 核心技术 1.1 元数据 元素据是一个统称,从软件的展现角度来看窗体、页签、字段、从数据存储角度,包括表、列;从逻辑处理角度,包括处理、回调等,在TAP开发平台中会详细讲解各元素的定义与应用。 1.2 函数引擎 函数引擎…

c语言函数能改变指针吗,如何修改传递给C中函数的指针?

如果要这样做,则需要传入指向指针的指针。void barPush(BarList ** list,Bar * bar){if (list NULL) return; // need to pass in the pointer to your pointer to your list.// if there is no move to add, then we are doneif (bar NULL) return;// allocate s…

Feature Engineering 特征工程 3. Feature Generation

文章目录1. 组合特征2. 过去7天的数据3. 上一个相同类型的项目的时间4. 转换数值特征learn from https://www.kaggle.com/learn/feature-engineering上一篇:Feature Engineering 特征工程 2. Categorical Encodings 下一篇:Feature Engineering 特征工程…

C# 转繁体转简体转拼音,超级文本大转换

最近项目中遇到一个需求:把员工的中文姓名根据系统配置转换成中文简体或中文繁体。 原以为需要一个很大的一个简体和繁体相对应的字符对应表之类的东西。 后来发现,VB中就包含了这样的函数Strings.StrConv(this.TextBox1.Text.Trim(), VbStrConv.Traditi…

c语言程序stm8s,经典STM8s20实用C语言编程大全

经典STM8s20实用C语言编程大全我学单片机开门三砖总是要砸的。第一砖:电源系统,这没什么好说的,只是它是stm8工作的基础总是要提一下第二砖:时钟系统,这等下再说。第三砖:复位系统,stm8只需要一…

Feature Engineering 特征工程 4. Feature Selection

文章目录1. Univariate Feature Selection 单变量特征选择2. L1 regularization L1正则learn from https://www.kaggle.com/learn/feature-engineering上一篇:Feature Engineering 特征工程 3. Feature Generation 经过各种编码和特征生成后,通常会拥有…

分销平台使用手册

分销平台使用手册 分销商和供应商流程图 基本资料维护 1、分销联系人资料:包括:联系人;联系固话(手机号码);email;阿里旺旺(建议用已认证过的账号或商城店铺的阿里旺旺子账号&#x…

非常好的C语言章节习题集带答案,非常好的C语言章节习题集带答案选编.doc

非常好的C语言章节习题集带答案选编PAGE \* MERGEFORMAT 90第1章 认识C语言二、习题(一)、是非题1.程序是指挥计算机进行各种信息处理任务的一组指令序列。A.对 B.错2.机器语言与硬件平台相关,但汇编语言和硬件平台无关。A.对 B.错3.编译型高级语言明显优于解释型高…

LeetCode 662. 二叉树最大宽度(递归)

1. 题目 给定一个二叉树,编写一个函数来获取这个树的最大宽度。树的宽度是所有层中的最大宽度。这个二叉树与满二叉树(full binary tree)结构相同,但一些节点为空。 每一层的宽度被定义为两个端点(该层最左和最右的非…

生物信息考研C语言,四川大学生物信息学初试经验分享

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼关于生物学(656):我所用的教材是《陈阅增普通生物学》。以及陈增阅的普生的配套练习册。今年还加了两本参考书 动物生物学和植物生物学题型:1.选择(10个,每个2分) 2.判断(10个,每个2分…

LeetCode 474. 一和零(01背包动态规划)

1. 题目 在计算机界中,我们总是追求用有限的资源获取最大的收益。 现在,假设你分别支配着 m 个 0 和 n 个 1。另外,还有一个仅包含 0 和 1 字符串的数组。 你的任务是使用给定的 m 个 0 和 n 个 1 ,找到能拼出存在于数组中的字…

LeetCode 452. 用最少数量的箭打破气球(贪心)

1. 题目 在二维空间中有许多球形的气球。对于每个气球,提供的输入是水平方向上,气球直径的开始和结束坐标。 由于它是水平的,所以y坐标并不重要,因此只要知道开始和结束的x坐标就足够了。 开始坐标总是小于结束坐标。平面内最多存…

android发展的外文文献综述,android文献综述总结.docx

android文献综述总结单位代码01  学号  分类号TP315  密级  文献综述  AJAXWeb应用程序开发技术的讨论  院名称  专业名称  学生姓名  指导教师  信息工程学院计算机科学与技术高博张亚娟  XX年2月21日  AJAXWeb应用程序开发技术的讨论  摘要  传统…

如何通过对方IP地址查对方的MAC

ping 对方IP 在用arp -a 查看机器上的arp缓存,其中一个是你自己机器的还有个就是那个IP的用ipconfig /all 查自己的MAC地址查同网段其他机器的nbtstat -A ip 或者 ping过的IP地址其主机nic的mac地址都会保存到arp缓存里面用arp -a就可以查看里面的内容。&#xff0…

Web 安全之文件下载漏洞详解

目录 引言 文件下载漏洞原理 文件下载漏洞的危害 文件下载漏洞类型 文件下载漏洞的利用方法 文件下载漏洞示例 文件下载漏洞的防护措施 漏洞检测与测试 小结 引言 在数字化时代,文件下载是网络应用程序的重要的功能之一,用户可以通过这一功能获…

android es管理工具,Android

Android ES文件管理器在文件管理器中,ES文件管理器的名气是比较大的,这款文件管理器也在近日进行了更新,更新后的ES文件管理器支持了更多网络存储空间,可以直接访问百度网盘、快盘、酷盘、微盘、box、sugarsync、dropbox和skydriv…

深入浅出InfoPath——让管理员来部署InfoPath表单

应用场景: 我们(乙方)在给客户提供基于InfoPath表单(尤其是包含托管代码的)的工作流解决方案的时候,常常需要客户(甲方)的SharePoint管理员来帮忙在安装SharePoint Server的服务器上…

LeetCode 932. 漂亮数组(分治递归/循环)

文章目录1. 题目2. 解题2.1 分治递归2.2 循环1. 题目 对于某些固定的 N&#xff0c;如果数组 A 是整数 1, 2, …, N 组成的排列&#xff0c;使得&#xff1a; 对于每个 i < j&#xff0c;都不存在 k 满足 i < k < j 使得 A[k] * 2 A[i] A[j]。 那么数组 A 是漂亮…

android 修改系统参数设置,2021-05-15 [RK3399][Android7.1] 调试笔记 ---显示参数动态设置接口...

系统环境&#xff1a;Platform: RK3399OS: Android 7.1Kernel: v4.4.83接口代码所在位置为&#xff1a;/frameworks/base/core/java/android/os/DisplayOutputManager.java如图&#xff1a;image.png1. 设置背光亮度public void setBrightness(int display, int brightness)设置…

Lucene.Net:关于索引的一些补充说明和总结

在前面的几篇关于lucene的文章中&#xff0c;我已经简要说明了如何利用lucene进行分词、索引和搜索。最近大部分时间耗在查资料上&#xff0c;看得比较多比较杂但是一贯的不够深入&#xff0c;还好多数都是不会影响编程实践的概念性的东西。有时候我自己也感觉到有心无力&#…