liblinear-java

Java port of the original C++ sources.

Download .jar Download .zip View on GitHub

Maven

Liblinear is available via the official Maven repository.

<dependency>
    <groupId>de.bwaldvogel</groupId>
    <artifactId>liblinear</artifactId>
    <version>1.94</version>
</dependency>

Usage

The usage is pretty similar to the C++ library version.

Standalone

$ java -cp liblinear-1.94.jar de.bwaldvogel.liblinear.Train -v 5 rcv1_train.binary
nSV = 6020
time: 935 ms
correct: 19637
Cross Validation Accuracy = 97.0112%

Java API

Problem problem = new Problem();
problem.l = ... // number of training examples
problem.n = ... // number of features
problem.x = ... // feature nodes
problem.y = ... // target values

SolverType solver = SolverType.L2R_LR; // -s 0
double C = 1.0;    // cost of constraints violation
double eps = 0.01; // stopping criteria

Parameter parameter = new Parameter(solver, C, eps);
Model model = Linear.train(problem, parameter);
File modelFile = new File("model");
model.save(modelFile);
// load model or use it directly
model = Model.load(modelFile);

Feature[] instance = { new FeatureNode(1, 4), new FeatureNode(2, 2) };
double prediction = Linear.predict(model, instance);

Weka

There is a Weka wrapper that can be installed using the Weka Package Manager.