2013-10-29 2 views
0

584 개의 특징 벡터 (총 100 개의 학습 벡터)가있는 각 데이터가있는 584 x 100 데이터 세트가 있습니다. Java에서 Libsvm을 구현했습니다. (1). trainX 크기는 584 x 100, (2). biny는 클래스 1의 경우 +1, 클래스 2의 경우 -1, LinearSVMNormVector는 모델의 결과 w (가중치 벡터)입니다.).바이너리 분류기가 잘못된 결과를 내고 있습니다.

   // scale train data between 0 and 1 
     double[][] trainX_scale = new double[trainX.length][trainX[0].length]; 
     for (int i = 0; i < trainX.length; i++) { 
      double min = Double.MAX_VALUE; 
      double max = Double.MIN_VALUE; 
      for (int inner = 0; inner < trainX[i].length; inner++) { 
       if (trainX[i][inner] < min) 
        min = trainX[i][inner]; 
       if (trainX[i][inner] > max) 
        max = trainX[i][inner]; 
      } 
      double difference = max - min; 
      for (int inner = 0; inner < trainX[i].length; inner++) { 
       trainX_scale[i][inner] = (trainX[i][inner] - min)/ difference; 
      } 
     } 

    // prepare the svm node 
     svm_node[][] SVM_node_Train = new svm_node[trainX[0].length][trainX.length]; 

     for (int p = 0; p < trainX[0].length; p++) { 
      for (int q = 0; q < trainX.length; q++) { 
       SVM_node_Train[p][q] = new svm_node(); 
       SVM_node_Train[p][q].index = q; 
       SVM_node_Train[p][q].value = trainX_scale[q][p]; 
      } 
     } 

     double[] biny_SVM = new double[biny.length];// for svm compatible 
     for (int p = 0; p < biny.length; p++) { 
      biny_SVM[p] = biny[p]; 
     } 

     svm_problem SVM_Prob = new svm_problem(); 
     SVM_Prob.l = trainX[0].length; 
     SVM_Prob.x = SVM_node_Train; 
     SVM_Prob.y = biny_SVM; 

     svm_parameter SVM_Param = new svm_parameter(); 
     SVM_Param.svm_type = 0; 
     SVM_Param.kernel_type = 2; 
     SVM_Param.cache_size = 100; 
     SVM_Param.eps = 0.0000001; 
     SVM_Param.C = 1.0; 
     SVM_Param.gamma = 0.5; 

     svm_model SVM_Model = new svm_model(); 
     SVM_Model.param = SVM_Param; 
     SVM_Model.l = trainX[0].length; 
     SVM_Model.nr_class = 2; 
     SVM_Model.SV = SVM_node_Train; 
     //SVM_Model.label = biny; 

     // String check =svm.svm_check_parameter(SVM_Prob, SVM_Param); // 
     // System.out.println(check); 

     double[] target = new double[biny.length];// for svm compatible 
     Arrays.fill(target, 0.0); 
     svm.svm_cross_validation(SVM_Prob, SVM_Param, 2, target); 

     // train the classifier 
     svm_model test_model = svm.svm_train(SVM_Prob, SVM_Param); 

     /********** get the training results of libsvm **********/ 

     //double[][] weights1 = test_model.sv_coef; 

     double Bias = test_model.rho[0]; 
     double NumberOfSupportVectors = svm.svm_get_nr_sv(test_model); 

     double [] SupportVectorIDs = new int[NumberOfSupportVectors]; 
     svm.svm_get_sv_indices(test_model, SupportVectorIDs); 
     svm_node[][] SV= test_model.SV; 
     double [][]SupportVectors=new double [SV.length][SV[0].length]; 
     for(int ii=0;ii<SV.length;ii++){ 
      for(int jj=0;jj<SV[0].length;jj++){ 
       SupportVectors[ii][jj]=SV[ii][jj].value; 
      } 
     } 
     double[] SupportVectorWeights=test_model.sv_coef[0]; 
     double[] LinearSVMNormVector = new double [SupportVectors[0].length]; 
     for (int ii=0;ii<msvm[0].SupportVectors[0].length;ii++){ 
      for (int jj=0;jj<SupportVectors.length;jj++){ 
       LinearSVMNormVector[ii] += (SupportVectors[jj][ii] * SupportVectorWeights[jj]); 
      } 

     } 

지원 벡터의 수가 제한된 지원 벡터의 수는 56이 될 수 100 인 경우 svm_train의 결과가 this-

optimization finished, #iter = 25 
    nu = 0.9999999995725399 
    obj = -24.999999987969172, rho = 1.1534070678518276E-10 
    nSV = 50, nBSV = 26 
    Total nSV = 50 
    * 
    optimization finished, #iter = 25 
    nu = 0.9999999998014489 
    obj = -24.999999994976864, rho = -4.654032538963752E-10 
    nSV = 50, nBSV = 28 
    Total nSV = 50 
    * 
    optimization finished, #iter = 50 
    nu = 0.9999999994269334 
    obj = -49.999999961945335, rho = -4.303699855872079E-10 
    nSV = 100, nBSV = 56 
    Total nSV = 100 

처럼이 코드 - 다음은 내 코드는? 나는 조금 혼란 스럽다 누군가이 분류기가 작동하지 않는 이유를 말해 줄 수 있습니까?

감사합니다.

답변

0

분류기가 올바르게 작동한다고 생각합니다. 하지만 바이너리 클래스 및 다중 차원과 혼동하는 것 같습니다. 바이너리 클래스를 사용하는 경우에도 해당 기능에 대해 100 개의 차원이 있으며 가우스 커널을 사용하여 분류 할 수 있습니다.

커널은 선형 모델처럼 취급하여 기능을 분류하는 데 도움이됩니다. 그래서 그것은 높은 차원 공간에 대한 결정 경계를 가질 수 있습니다. 고차원 피처에는 많은 경계지지 벡터가있을 수 있습니다.

그래서 분류기가 잘 작동한다고 생각합니다.

귀하의 질문에 도움이되기를 바랍니다. 나도 지금 기대고있어, 이상하고 명확하지 않다고 생각하면 언제든지 말해주세요.

관련 문제