liblinear-java icon indicating copy to clipboard operation
liblinear-java copied to clipboard

Is a bias term added to the features automatically?

Open bmccord2 opened this issue 3 years ago • 2 comments

I am maintaining code that I mostly didn't write which uses liblinear for logistic regression. My understanding from the documentation was that setting bias to a value greater than 0 will result in a synthetic feature being added. But I cannot see anywhere in the code where this feature is added either during training or prediction. Is it required to both set the bias parameter to a value greater than 1 and also manually add the synthetic feature node during training and prediction?

bmccord2 avatar Feb 08 '22 19:02 bmccord2

Yes, the bias feature is added automatically, if bias is ≥ 0. You can find all the places in the code, when you search for bias >= 0. Please note that I just translated this logic from the original C++ sources. I would have probably designed it in a slightly different way ;)

bwaldvogel avatar Feb 09 '22 08:02 bwaldvogel

Hey thanks for your reply! Yeah I realize the code is autogenerated, so I didn't know if I should ask here or in the c++ project. Looking over the code, I see that a feature node is initialized with a value of new FeatureNode(n, model.bias) in the Train and Predict scripts, but that doesn't appear happen in the static functions provided by the Linear class from what I can tell. I'm not sure if it happens in the C++ code. It looks essentially the same to me, but I am not 100%.

I noticed that my generated models end up with a bias weight of 0, so thats what has me wondering about this. For clarification I am not using the commandline scripts, I am using the linear static functions directly.

bmccord2 avatar Feb 10 '22 23:02 bmccord2