libsvm-ruby-swig icon indicating copy to clipboard operation
libsvm-ruby-swig copied to clipboard

Unbalanced data / weights

Open pgswartz opened this issue 12 years ago • 4 comments

Hi Tom et al, I'm dealing with some pretty unbalanced data and was trying to define the parameters necessary for assigning my own weights. I'm doing the following:

pa = Parameter.new
pa.nr_weight = 2
pos_weight = 1 - clean_positive_train.size/(clean_positive_train.size + clean_negative_train.size)
pa.weight_label([positive_label,negative_label])
pa.weight([pos_weight, 1-pos_weight])

This results in a segmentation fault. I can avoid this segmentation fault by setting nr_weight to 0, but as I understand it, this will mean no weights are assigned (i.e., all classes get weight 1). Could I please ask for your advice on what I'm doing wrong?

Thanks for the awesome library! Peter

pgswartz avatar Jul 08 '13 15:07 pgswartz

Changed my code a bit, based on errors, to:

pa = Parameter.new pa.nr_weight = 2 pos_weight = 1 - clean_positive_train.size.to_f/(clean_positive_train.size.to_f + clean_negative_train.size.to_f) pa.weight_label = [positive_label,negative_label] pa.weight = [pos_weight, 1-pos_weight]

Seems to be working now... Will be in touch with results

pgswartz avatar Jul 09 '13 15:07 pgswartz

Sorry, I'm reopening. I'm using the above formulation, but even adjusting my weights in an exaggerated manner (i.e., assign positive weight = 10^-5 and negative_weight =1) does not fundamentally change my results in any real way. I am assigning weights incorrectly, or would you have other advice? Thank you, PGS

pgswartz avatar Jul 10 '13 20:07 pgswartz

Hi Peter,

Thanks for pointing this out, at this point I don't have much idea, I am planning to rewrite this at some point. The results of earlier versions of the gem were verified by the LIBSVM developers, the gem then got upgraded to make use of newer versions of LIBSVM, so it's possible that the weighted input may not be working.

Tom

tomz avatar Jul 10 '13 20:07 tomz

Hi Tom, Thanks for the message. I'll keep investigating, will update this thread with my findings. Very much appreciate the cool gem you've made! Peter

pgswartz avatar Jul 10 '13 20:07 pgswartz