Vote count:
0
I am using Java to run a minimal example of a two class SVM model. All the training points are in a text file formatted in the recommended way by lbsvm. label index:value....
0 1:0.0 2:1.5336402654647827 3:0.0 4:0.0 5:0.0 6:1.5336402654647827 7:1.5336402654647827 8:0.0
1 1:0.0 2:0.0 3:0.0 4:1.8472979068756104 5:1.8472979068756104 6:0.0 7:0.0 8:1.8472979068756104
...
When I use the libsvm via command line (svm-train train.txt), I get the following output results for my model
optimization finished, #iter = 11
nu = 0.021188
obj = -1.409060, rho = 0.034411
nSV = 4, nBSV = 0
Total nSV = 4
The test set has decent results and classifies the points correctly. I used the default parameters as defined in the README.
But when I run it in my Java program, I get the following results for the model training,
optimization finished, #iter = 56
nu = 0.8421052631578947
obj = -112.0, rho = -1.0
nSV = 112, nBSV = 112
Total nSV = 112
I read the same data file in using the following method:
public void readSampleData()
{
BufferedReader bufReader = null;
FileReader reader = new FileReader("libsvmTrain.txt");
bufReader = new BufferedReader(reader);
String line;
svmProb = new svm_problem();
svmProb.l = 133;
svmProb.x = new svm_node[133][];
svmProb.y = new double[133];
try {
int trainPt = 0;
while ((line = bufReader.readLine()) != null)
{
String[] coords = line.split(" ");
//First one is label
svmProb.y[trainPt] = Doubles.tryParse(coords[0]);
svmProb.x[trainPt] = new svm_node[coords.length-1];
for (int i = 1; i < coords.length; i++)
{
svm_node node = new svm_node();
String[] point = coords[i].split(":");
node.index = Integer.parseInt(point[0]);
node.value = Doubles.tryParse(point[1]);
svmProb.x[trainPt][i-1] = node;
}
trainPt++;
}
reader.close();
And below are the default parameters:
svmParam = new svm_parameter();
// default values
svmParam.svm_type = svm_parameter.C_SVC;
svmParam.kernel_type = svm_parameter.RBF;
svmParam.degree = 3;
svmParam.gamma = 0; // 1/num_features
svmParam.coef0 = 0;
svmParam.nu = 0.5;
svmParam.cache_size = 100;
svmParam.C = 1;
svmParam.eps = 1e-3;
svmParam.p = 0.1;
svmParam.shrinking = 1;
svmParam.probability = 0;
svmParam.nr_weight = 0;
svmParam.weight_label = null;
svmParam.weight = null;
I use svm.svm_train(svmProb, svmParam). Not only does the training result in an output very different but it classifies everything in the test set with a 0 label.
Is there some bug in libsvm regarding the command line version versus the java library?
Aucun commentaire:
Enregistrer un commentaire