博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Keras 处理 不平衡的数据的分类问题 imbalance data 或者 highly skewed data
阅读量:4262 次
发布时间:2019-05-26

本文共 1264 字,大约阅读时间需要 4 分钟。

处理不平衡的数据集的时候,可以使用对数据加权来提高数量较小类的被选中的概率,具体方式如下

 

fit(self, x, y, batch_size=32, nb_epoch=10, verbose=1, callbacks=[], validation_split=0.0, validation_data=None, shuffle=True, class_weight=None, sample_weight=None)

class_weight:字典,将不同的类别映射为不同的权值,该参数用来在训练过程中调整损失函数(只能用于训练)

sample_weight:权值的numpy array,用于在训练时调整损失函数(仅用于训练)。可以传递一个1D的与样本等长的向量用于对样本进行1对1的加权,或者在面对时序数据时,传递一个的形式为(samples,sequence_length)的矩阵来为每个时间步上的样本赋不同的权。这种情况下请确定在编译模型时添加了sample_weight_mode=’temporal’。

 

具体使用可以如下:

设置不同累的权值,如下:类0,权值1;类1,权值50

cw = {0: 1, 1: 50}

训练模型

model.fit(x_train, y_train,batch_size=batch_size,epochs=epochs,verbose=1,callbacks=cbks,validation_data=(x_test, y_test), shuffle=True,class_weight=cw)

 

如果仅仅是类不平衡,则使用class_weight,sample_weights则是类内样本之间还不平衡的时候使用。

class_weight affects the relative weight of each class in the calculation of the objective function.

sample_weights, as the name suggests, allows further control of the relative weight of samples that belong to the same class.

 Class weights are useful when training on highly skewed data sets; for example, a classifier to detect fraudulent transactions.

Sample weights are useful when you don't have equal confidence in the samples in your batch. A common example is performing regression on measurements with variable uncertainty.

转载地址:http://cqlei.baihongyu.com/

你可能感兴趣的文章
android 操作系统
查看>>
button事件的两种处理方法
查看>>
android 震动
查看>>
【数据结构与算法】(四) c 语言静态队列的简单实现
查看>>
[linux] unix domain socket 例子
查看>>
[linux] c 实现简单的web服务器
查看>>
栈--判断回文字符串
查看>>
解决 The `master` repo requires CocoaPods 1.0.0 - (currently using 0.39.0)
查看>>
gdb调试常用命令
查看>>
vim正则表达式批量修改文本
查看>>
【Lintcode】寻找峰值
查看>>
Arduino 串口读写 SD 卡模块
查看>>
图的基本算法--深度优先搜索(dfs) 和 广度优先搜索(bfs)
查看>>
[Linux] Linux内核编译安装过程,及Linux源码目录结构
查看>>
[Linux] c语言变量的存储位置-笔记
查看>>
[Linux] 头文件实质-笔记
查看>>
统一修改iOS中xib颜色值
查看>>
数据湖与数据仓库的新未来:阿里提出湖仓一体架构
查看>>
基于Flink+ClickHouse打造轻量级点击流实时数仓
查看>>
Flink sink schema 字段设计小技巧
查看>>