Comments (4)
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.
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 FeatureNode
s.
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 FeatureNode
s (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.
@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.
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)
- Suppress output to console when using API HOT 2
- Port Liblinear weights
- how to get the separating hyperplane parameters or separating hyperplane equation? HOT 1
- Documentation For Java API HOT 2
- Overload Train.readProblem to take an InputStream instead of File HOT 3
- No option for no bias feature for Train.readProblem() HOT 1
- Different Results With the Same Experiment HOT 4
- InvalidInputDataException: indices must be sorted in ascending order (line 479) HOT 1
- Bias term is added by default HOT 2
- Implement init_sol setter in Parameter
- How to obtain the support vectors
- Thread safety problem in predict: flag_predict_probability shouldn't be static HOT 3
- NullPointerException when using sparse data to train Model HOT 1
- Linear's global RNG makes it difficult to reproduce models or track concurrent executions HOT 6
- Is a bias term added to the features automatically? HOT 2
- Does liblinear-java support incremental training?
- Performance improvements
- 你好我在用这个东西 HOT 4
- Setting HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from liblinear-java.