jLibSvm:如何为格式良好的列车设置参数

时间:2017-08-10 14:15:19

标签: svm libsvm

我正在尝试使用jLibSvm来训练所有相同类型的生物识别数据。 有5类标记有字符串的数据。 我已尝试使用MultiClassModel或BinaryModel,但在这两种情况下,任何预测都会返回相同的结果,即使通过更改gamma值。

下面是我的MultiClassModel代码:

public static <L,SparseVector> void train(Map<SparseVector,L> examples){    
        MultiClassificationSVM svm = new MultiClassificationSVM(new C_SVC());

        ImmutableSvmParameterPoint.Builder builder = new ImmutableSvmParameterPoint.Builder();
        builder.C = 1.0;
        builder.kernel = new GaussianRBFKernel(0.001);
        builder.eps = 0.1f;

        ImmutableSvmParameter params = builder.build();

        MutableMultiClassProblemImpl problem = 
                new MutableMultiClassProblemImpl(String.class, null,
                        examples.size(), new NoopScalingModel());

        problem.examples = examples;
        for( SparseVector v : examples.keySet() )
            problem.exampleIds.put(v, problem.exampleIds.size());

        model = svm.train(problem, params);
    }

和BinaryModel:

public static <L> void train(List<SparseVector> exTrue, List<SparseVector> exFalse, String label){ 
        C_SVC svm = new C_SVC();

        ImmutableSvmParameterPoint.Builder builder = new ImmutableSvmParameterPoint.Builder();
        builder.C = C;
        builder.kernel = new GaussianRBFKernel(gamma);
        builder.eps = 0.001f;

        ImmutableSvmParameter params = builder.build();

        MutableBinaryClassificationProblemImpl problem
            = new MutableBinaryClassificationProblemImpl(String.class, exTrue.size()+exFalse.size());

        for(SparseVector v : exTrue)
            problem.addExample(v, label);

        String inverse = new StringLabelInverter().invert(label);
        for(SparseVector v : exFalse)
            problem.addExample(v, inverse);

        BinaryModel bm = svm.train(problem, params);        
        models.put(label, bm);
    }

0 个答案:

没有答案