tomz / libsvm-ruby-swig

Ruby interface to LIBSVM (using SWIG)
Other
110 stars 24 forks source link

Unbalanced data / weights #9

Open pgswartz opened 11 years ago

pgswartz commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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

tomz commented 11 years ago

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

pgswartz commented 11 years ago

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