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!
Below is my code:
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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…