python imblearn toolbox 解决数据不平衡问题(一)——imblearn简介

我们在处理医疗诊断等问题,会遇到不平衡数据,即病人的数据量相对于正常人的数据量要小的多。而大多数机器学习算法需要较为平衡的数据。如果不对不平衡数据处理,往往会导致模型向majority class方向偏移。在Python中,有个很好用的库imbalanced-learn——imblearn.在本博文,只借鉴论文进行关键点总结。

参考

先放参考,后文是我在阅读参考资料时整理的笔记,因此难免疏漏.
论文网址
Github
文档

实现的采样方法

  1. Under-sampling:即下采样,减少多数样本的数量;
  2. Over-sampling:即上采样,生成少数样本;
  3. Over-sampling followed by under-sampling:先上采样再下采样,防止过拟合;
  4. Ensemble classifier using samplers internally:集成学习的方法.

win10安装

pip install imblearn
  • 依赖:numpy, scipy, scikit-learn

使用方式

与sklearn相似,主要是fitfit_resample.论文中给出的一个例子为:

#基本用法
from sklearn.datasets import make_classification 
from sklearn.decomposition import PCA 
from imblearn.over_sampling import SMOTE

#Generate the dataset
x, y = make_classification(n_classes=2,weights=[0,1,0.9],
                           n_features=20,n_samples=5000)

#Apply the SMOTE over-sampling
sm = SMOTE(ratio='auto', kind='regular') #可选其它采样方式
X_resampled, y_resampled = sm.fit_resample(X,y)

samplers的调用方法

  • Way1
estimator = obj.fit(data, target) 
  • Way2
data_resampled, target_resampled = obj.fit_resample(data, targets)

可以接受的input数据格式:

data: array-like (2-D list, pandas.Dataframe or numpy.array) or sparse
matrices targets: array-like(1-D list, pandas.Serise, numpy.array)

  • 3
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值