Coder Social home page Coder Social logo

Comments (4)

zenogantner avatar zenogantner commented on May 30, 2024

Hello,

Have a look at this line here:

if (model.bias >= 0)
            n = model.nr_feature + 1;

This leads to the bias term being included in the weight vector.

You can double check for your case by writing out your weight vector and see whether it has 2 or 3 entries. I would guess it will have 3.

The code is a bit confusing to Java developers because it is ported from C++, and kept very similar to the original source for maintainability reasons -- see the README.

from liblinear-java.

tommilata avatar tommilata commented on May 30, 2024

Hello,

thanks for your quick reply.

Maybe I should describe my use case a little more.

I'm using liblinear-java only for inference, doing training separately (not using liblinear for training).
My trained model uses 2 features and has e.g. coefficients w1=1 w2=-2 and bias=3.

I'm loading the model from a file that I construct manually and using Linear.predictProbability() directly for inference directly (not using the CLI).

I'd like my prediction score to be calculated as w1*x1 + w2*x2 + bias. For that, I'd expect the right way to write the model file to be

solver_type L2R_LR
nr_class 2
label 1 0 
nr_feature 2
bias 3.0000000000000000 
w
1.0000000000000000 
-2.0000000000000000 

and to run the inference with an array of 2 FeatureNodes.

But that doesn't seem to add the bias to the sum. Yes, due to

if (model.bias >= 0)
            n = model.nr_feature + 1;

, n is increased, but bias does not seem to be added to the w vector.

I managed to get expected results by modifying to model from above to

solver_type L2R_LR
nr_class 2
label 1 0 
nr_feature 3
bias -1
w
1.0000000000000000 
-2.0000000000000000 
3.0000000000000000 

and then calling Linear.predictProbability() with an array of 3 FeatureNodes (the last one with value of 1). I basically replaced the bias constant with a 3rd feature with a constant value of 1 and w3=<original bias>.

Am I misunderstanding something about how the bias parameter is supposed to work?

from liblinear-java.

bwaldvogel avatar bwaldvogel commented on May 30, 2024

@tomas-milata: Could you do me a favor and check if the Java implementation¹ does exactly the same thing as the C++ version?

If yes, please file this issue in https://github.com/cjlin1/liblinear.

¹ the part of the code that is relevant for this issue

from liblinear-java.

tommilata avatar tommilata commented on May 30, 2024

Hi! Sorry, I've found a workaround for this, my project is finished and don't have capacity to check this.

from liblinear-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.