I have attached the link to the stack overflow question page under. In short it is a Class imbalance problem in binary classification of ecg and eeg data.



1 Answer 1


In your question, you say this:

This leads to a class imbalance in the ratio 1:7 (fear:not fear). I am getting false accuracies in the 90% range due to this.

To be pedantic, this is not a "false" accuracy. The accuracy metric is being computed correctly. The issue is accuracy is not a meaningful metric for problems with high class imbalance.

Consider something like fraud detection where 99.9+% of examples are negative. A model that guessed "not fraud" for everything would achieve 99.9+% accuracy. Unfortunately, that model is not very useful.

When modeling with a large class imbalance, you need to use a metric that accounts for class imbalance. The usual metrics in this case are precision and recall. Precision looks at the false positive rate, recall looks at the false negative rate. Typically you have a tradeoff between the two - ie higher precision models tend to have lower recall. The correct metric for your problem depends on if you care more about false positives or false negatives.

To use a different metric, update this line in your code with a different scoring metric:

a_score = cross_val_score(model, data, target, cv=kFolds, scoring='accuracy')

You can find the sklearn standard supported metrics here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.