我正在尝试使用高度不平衡的数据集执行二进制分类。我的目标值是0(84%)和1(16%)。我在我的模型中使用了class_weight,但是少数类的精度和召回总是0.我不确定我是否正确使用class_weights。真的很感激任何帮助!
以下是我的代码:
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