不平衡数据的class_weight-Keras [英] class_weight for imbalanced data - Keras

查看:106
本文介绍了不平衡数据的class_weight-Keras的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用高度不平衡的数据集执行二进制分类.我的目标值为0(84%)和1(16%).我在模型中使用了class_weight,但是少数类的精度和召回率始终为0.我不确定我是否正确使用了class_weights.非常感谢您提供任何帮助!

I am trying to perform binary classification with a highly imbalanced dataset. My target values are 0(84%) and 1 (16%). I used class_weight in my model but the precision and recall for the minority class is always 0. I am not sure if i am using class_weights correctly. Would really appreciate any help on this!

下面是我的代码:

class_weight = {0:1,1:50}
numpy.random.seed(5)

model = Sequential()
model.add(Dense(13,input_dim = 5, activation='relu'))
model.add(Dense(13, activation='relu'))
model.add(Dense(10, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

model.compile(loss="binary_crossentropy", optimizer = "adam", metrics = ['accuracy'])
model.fit(X_train,Y_train, epochs = 10, batch_size = 30, class_weight = class_weight, validation_data = (X_test, Y_test))
preds = model.predict_classes(X_test)
print (classification_report(Y_test, preds))

           precision    recall  f1-score   support

      0       0.83      1.00      0.91     24126
      1       0.00      0.00      0.00      4879

推荐答案

没有足够的声誉来添加评论.因此写作作为 答案.

Don't have enough reputation to add a comment. Hence writing as an answer.

您说您的班级失衡是84:16(大约5:1),但您发送的班级2是班级1的50倍.尝试在5-10之间输入一些值

You say your class imbalance is 84:16 (5:1 approx) but you are sending your Class 2 50 times as Class 1. Try some value between 5-10

这篇关于不平衡数据的class_weight-Keras的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆