6
$\begingroup$

I'm facing a problem with unbalanced classes, and have tried out a couple of methods like over and under sampling. However, my cross validation mean comes out to be only 0.4 and my confusion matrix shows that the prediction and recall is completely incorrect.

Ive read that the next step is to add weights to my class; I have two of them "Won" and "Lost". In Pandas, how am I supposed to assign weights to them? I know that there is a "class_weights" attribute, but I have no clue on how to use it.

Thanks

enter image description here

PS. My "Won" class is unbalanced, very small compared to the "Lost" one. I train by repeating the set of "Won"s twice and randomly sample an almost equal amount of "Lost"s. I've tried all sorts of combinations of the classes.

$\endgroup$
  • 1
    $\begingroup$ The easiest way (and first thing to try) is to set class_weight="balanced". See if that improves your score... $\endgroup$ – stmax May 3 '16 at 14:04
  • $\begingroup$ Thanks, but I tried that and the O/P wasn't any better. Is 'auto' also an option for class_weight? I tried using a dict like {'Lost':0.5,'Won':1}, but that just threw an error $\endgroup$ – TdBm May 3 '16 at 14:12
  • $\begingroup$ But why didn't stmax suggestion work: > The easiest way (and first thing to try) is to set > class_weight="balanced". See if that improves your score... – stmax > May 3 '16 at 14:04 $\endgroup$ – Pobo Jul 5 '18 at 17:23
8
$\begingroup$

Maybe try to encode your target values as binary. Then, this class_weight={0:1,1:2} should do the job. Now, class 0 has weight 1 and class 1 has weight 2.

$\endgroup$
  • 1
    $\begingroup$ HonzaB you are a legend!!! Thanks for your help, it worked. Now to grid search some possible combinations... $\endgroup$ – TdBm May 4 '16 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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