Search in sources :

Example 1 with Parameter

use of de.bwaldvogel.liblinear.Parameter in project dkpro-tc by dkpro.

the class LiblinearTestTask method trainModel.

@Override
protected Object trainModel(TaskContext aContext) throws Exception {
    File fileTrain = getTrainFile(aContext);
    // default for bias is -1, documentation says to set it to 1 in order to
    // get results closer
    // to libsvm
    // writer adds bias, so if we de-activate that here for some reason, we
    // need to also
    // deactivate it there
    Problem train = Problem.readFromFile(fileTrain, 1.0);
    SolverType solver = LiblinearUtils.getSolver(classificationArguments);
    double C = LiblinearUtils.getParameterC(classificationArguments);
    double eps = LiblinearUtils.getParameterEpsilon(classificationArguments);
    Linear.setDebugOutput(null);
    Parameter parameter = new Parameter(solver, C, eps);
    Model model = Linear.train(train, parameter);
    return model;
}
Also used : Model(de.bwaldvogel.liblinear.Model) Parameter(de.bwaldvogel.liblinear.Parameter) Problem(de.bwaldvogel.liblinear.Problem) SolverType(de.bwaldvogel.liblinear.SolverType) File(java.io.File)

Example 2 with Parameter

use of de.bwaldvogel.liblinear.Parameter in project dkpro-tc by dkpro.

the class LiblinearSerializeModelConnector method trainModel.

@Override
protected void trainModel(TaskContext aContext, File fileTrain) throws Exception {
    SolverType solver = LiblinearUtils.getSolver(classificationArguments);
    double C = LiblinearUtils.getParameterC(classificationArguments);
    double eps = LiblinearUtils.getParameterEpsilon(classificationArguments);
    Linear.setDebugOutput(null);
    Parameter parameter = new Parameter(solver, C, eps);
    Problem train = Problem.readFromFile(fileTrain, 1.0);
    Model model = Linear.train(train, parameter);
    model.save(new File(outputFolder, MODEL_CLASSIFIER));
}
Also used : Model(de.bwaldvogel.liblinear.Model) Parameter(de.bwaldvogel.liblinear.Parameter) Problem(de.bwaldvogel.liblinear.Problem) SolverType(de.bwaldvogel.liblinear.SolverType) File(java.io.File)

Aggregations

Model (de.bwaldvogel.liblinear.Model)2 Parameter (de.bwaldvogel.liblinear.Parameter)2 Problem (de.bwaldvogel.liblinear.Problem)2 SolverType (de.bwaldvogel.liblinear.SolverType)2 File (java.io.File)2