当前位置:网站首页>一个简单但是能上分的特征标准化方法
一个简单但是能上分的特征标准化方法
2022-06-29 15:56:00 【deephub】
一般情况下我们在做数据预处理时都是使用StandardScaler来特征的标准化,如果你的数据中包含异常值,那么效果可能不好。
这里介绍的方法叫Robust Scaling,正如它的名字一样能够获得更健壮的特征缩放结果。与StandardScaler缩放不同,异常值根本不包括在Robust Scaling计算中。因此在包含异常值的数据集中,更有可能缩放到更接近正态分布。
StandardScaler会确保每个特征的平均值为0,方差为1。而RobustScaler使用中位数和四分位数(四分之一),确保每个特征的统计属性都位于同一范围。
公式如下:

我们使用一些数据看看他的结果,首先创建测试数据
import numpy as np
import matplotlib.pyplot as plt
nb_samples = 200
mu = [1.0, 1.0]
covm = [[2.0, 0.0], [0.0, 0.8]]
X = np.random.multivariate_normal(mean=mu, cov=covm, size=nb_samples)
然后使用三个常用的缩放方法对数据进行预处理:
from sklearn.preprocessing import StandardScaler, RobustScaler, MinMaxScaler
ss = StandardScaler()
X_ss = ss.fit_transform(X)
rs = RobustScaler(quantile_range=(10, 90))
X_rs = rs.fit_transform(X)
mms = MinMaxScaler(feature_range=(-1, 1))
X_mms = mms.fit_transform(X)
可视化:
fig, ax = plt.subplots(2,2, sharex=True, sharey=True, dpi=1000)
ax[0][0].scatter(X[:,0], X[:,1], c='gray', alpha = .8)
ax[0][1].scatter(X_ss[:,0], X_ss[:,1], c='gray', alpha = .8)
ax[1][0].scatter(X_rs[:,0], X_rs[:,1], c='gray', alpha = .8)
ax[1][1].scatter(X_mms[:,0], X_mms[:,1], c='gray', alpha = .8)
ax[0][0].set_title('Original dataset')
ax[0][1].set_title('Standard Scaling')
ax[1][0].set_title('Robust Scaling')
ax[1][1].set_title('Min-Max Scaling')
plt.tight_layout()

为什么这个方法不会受异常值的影响?
如果数据中存在很大的异常值,可能会影响特征的平均值和方差进而影响标准化结果。而RobustScaler使用中位数和四分位数间距进行缩放,这样可以缩小异常值的影响.
最后我们再看一下这个方法的参数
quantile_range : tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0, default=(25.0, 75.0)
quantile_range用于计算scale_的分位数范围。默认情况下,它等于IQR,即q_min是第一个分位数,q_max是第三个分位数,也就是我们上面公式中的Q1和Q3.
https://avoid.overfit.cn/post/003377e07cdd4a7db3d4039979019bb8
作者:Simsangcheol
边栏推荐
- 南京大学:新时代数字化人才培养方案探讨
- 蓝桥杯几道全排列的题目
- 【第28天】给定一个字符串S,请你判断它是否为回文字符串 | 回文的判断
- 如何在你的 wordpress 网站中添加搜索框
- Sophon Base 3.1 推出MLOps功能,为企业AI能力运营插上翅膀
- 卫龙辣条第三次冲刺上市:业绩增速下滑,刘卫平、刘福平提前套现
- leetcode:232. Realize queue with stack [two stacks, one auxiliary and one simulated queue]
- Cv5200 ad hoc network remote WiFi module, UAV wireless image transmission application, HD low delay scheme
- Notice on organizing the declaration of Nanjing innovative products (the first batch) in 2022
- MATLAB输出格式控制 %d,%f,%c,%s的用法
猜你喜欢

Interviewer: tell me about the MySQL transaction isolation level?

leetcode:42. 接雨水【双指针很优雅】

DAP大屏主题开发说明

mysql数据库基础:数据类型介绍

UWB precise positioning scheme, centimeter level high-precision technology application, intelligent pairing induction technology

基于JSP实现毕业设计选题系统

星环科技数据安全管理平台 Defensor重磅发布

apache atlas断点查看

面试官:说一下MySQL事务隔离级别?

Huaxia Fund: sharing of digital transformation practice achievements in the fund industry
随机推荐
How to install WordPress on a web site
mysql数据库基础:数据类型介绍
如何在 WordPress 中创建登录页面
apache atlas断点查看
【大家的项目】 Rbatis ORM官网上线
Timecho of Tianmou technology completed Angel round financing of nearly RMB 100 million and built the original time series database of the industrial Internet of things around Apache iotdb
Daily / June 29, 2022: where is Li Feifei's focus on "embodied intelligence"?
CV5200自组网远程WiFi模组,无人机无线图传应用,高清低时延方案
Cerebral Cortex:从任务态和静息态脑功能连接预测儿童数学技能
MySQL error: expression 1 of order by claim is not in group by claim and contains nonaggregated column
Key sprite fighting monsters - window binding skill
How do I create a contact form in WordPress?
【Rust日报】 Rust 2021-稳定性
Science: the interrelated causes and consequences of sleep in the brain
工具链赋能百家,地平线开启智能驾驶量产的“马太效应”
mysql报错:Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column
基础 | 在物理引擎中画圆弧
Key wizard play monster learning - multi window and multi thread background judgment of character, pet blood volume and pet happiness
TLBB series of Tianlong Babu - online single use database modified to other sects
Which version of JVM is the fastest?