svm - one class classification libsvm in java -
i'm trying code one-class classification in java. defined 4 points in 2-d, (10,10), (-10,10), (10,-10), (-10,10), , test(0,0) classification, result -1, means (0,0) negative sample. doesn't make sense. here code.
import libsvm.svm; import libsvm.svm_model; import libsvm.svm_node; import libsvm.svm_parameter; import libsvm.svm_problem; public class testsvm { /** * @param args */ public static void main(string[] args) { //define points a{10.0, 10.0}, b{-10.0, -10.0}, c{10,-10}, d{-10,10}, , labels {1.0, 1.0, 1.0, 1.0} svm_node pa0 = new svm_node();pa0.index = 0;pa0.value = 10.0; svm_node pa1 = new svm_node();pa1.index = 1;pa1.value = 10.0; svm_node pb0 = new svm_node();pb0.index = 0;pb0.value = -10.0; svm_node pb1 = new svm_node();pb1.index = 1;pb1.value = -10.0; svm_node pc0 = new svm_node();pc0.index = 0;pc0.value = 10.0; svm_node pc1 = new svm_node();pc1.index = 1;pc1.value = -10.0; svm_node pd0 = new svm_node();pd0.index = 0;pd0.value = -10.0; svm_node pd1 = new svm_node();pd1.index = 1;pd1.value = 10.0; svm_node[] pa = {pa0, pa1}; //point svm_node[] pb = {pb0, pb1}; //point b svm_node[] pc = {pc0, pc1}; //point c svm_node[] pd = {pd0, pd1}; //point d svm_node[][] datas = {pa, pb,pc,pd}; //data trainning double[] lables = {1.0, 1.0, 1.0, 1.0}; //labels //define svm_problem svm_problem problem = new svm_problem(); problem.l = 4; //number of trainning data problem.x = datas; //trainning data problem.y = lables; //labels //define svm_parameter svm_parameter param = new svm_parameter(); param.svm_type = svm_parameter.one_class; param.kernel_type = svm_parameter.linear; param.cache_size = 100; param.eps = 0.00001; param.c = 1; param.nu = 0.01; //train svm system.out.println(svm.svm_check_parameter(problem, param)); //check svm_model model = svm.svm_train(problem, param); //get svm_model //test point e svm_node pe0 = new svm_node(); pe0.index = 0; pe0.value = 0.0; svm_node pe1 = new svm_node(); pe1.index = 1; pe1.value = 0.0; svm_node[] pe = {pe0, pe1}; //output label system.out.println(svm.svm_predict(model, pe)); } }
Comments
Post a Comment