liblinear-java

Java version of LIBLINEAR


liblinear-java

Maven

Liblinear is available via the official Maven repository.

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

Usage

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

Standalone

$ java -cp liblinear-2.44.jar de.bwaldvogel.liblinear.Train -v 5 rcv1_train.binary
nSV = 6021
time: 719 ms
correct: 19638
Cross Validation Accuracy = 97.0161%

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.

Fork me on GitHub