当前位置: 动力学知识库 > 问答 > 编程问答 >

java - LibSVM testin the model: i always get one result for all features

问题描述:

Im trying to use LibSVM with java,

When i try to predict the label i always get one result for all the features!

 param.svm_type = svm_parameter.NU_SVC;

param.kernel_type = svm_parameter.RBF;

param.gamma = 0.5;

param.nu = 0.4;

param.cache_size = 20000;

param.C = 1000;

param.eps = 0.001;

param.p = 0.1;

size de feature training SVM: 913

optimization finished, #iter = 453

nu = 0.9923329682365827

obj = -906.0, rho = 1.0

nSV = 906, nBSV = 906

Total nSV = 906

reel : 0.0 predict : 1.0

reel : 1.0 predict : 1.0

reel : 0.0 predict : 1.0

reel : 1.0 predict : 1.0

reel : 1.0 predict : 1.0

reel : 0.0 predict : 1.0

reel : 1.0 predict : 1.0

reel : 0.0 predict : 1.0

reel : 1.0 predict : 1.0

this is the prediction fonction!

public static void test( svm_model model, HashMap<Integer, Double> labelTest,

HashMap<Integer, HashMap<Integer, Double>> featuresTesting ) {

int NombreLigne = featuresTesting.size();

for ( Integer testInstance : featuresTesting.keySet() ) {

double label = labelTest.get( testInstance );

HashMap<Integer, Double> tmp = new HashMap<Integer, Double>();

tmp = featuresTesting.get( testInstance );

int numFeatures = tmp.keySet().size();

svm_node[] x = new svm_node[numFeatures];

int featureIndx = 0;

for ( Integer feature : tmp.keySet() ) {

x[featureIndx] = new svm_node();

x[featureIndx].index = feature;

x[featureIndx].value = tmp.get( feature );

featureIndx++;

}

double d = svm.svm_predict( model, x );

System.out.println( "real : " + label + " prediction : " + svm.svm_predict( model, x ) );

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: