2014-09-09 5 views
2

나는 weka 데이터 마이닝과 평가에 처음이다. 지금까지 나는 데이터 세트를 읽었습니다. 데이터 세트를 기반으로 내 데이터를 예측하고 싶습니다. 예를 들어 weka 도구가 제공 한 날씨 데이터 세트를 사용했습니다 . 그래서 나는 분류를 위해 Naive Bayes Classifier를 사용했습니다. 이제, 내 속성에 대한 확률 값을 얻었습니다. 이제는 데이터 세트를 사용하여 데이터를 예측하고 싶습니다. 예를 들어 sunny,70,85,TRUE을 주면 클래스 가치의 확률을 얻고 싶습니다. 지금까지이 부분을 해 보았습니다. 아무도 데이터 평가를 위해 Naive Bayes 분류자를 사용하는 방법을 말해 줄 수 있습니까?Java Naive Bayes 분류 자 ​​평가

public static void ArfLoader(){ 
     ArffLoader loader = new ArffLoader(); 
     try { 
      loader.setFile(new File("sampleData.txt")); 
      Instances structure = loader.getStructure(); 
      structure.setClassIndex(structure.numAttributes() - 1); 

      NaiveBayesUpdateable nb = new NaiveBayesUpdateable(); 
      nb.buildClassifier(structure); 
      Instance current; 
      while ((current = loader.getNextInstance(structure)) != null){ 
       nb.updateClassifier(current); 
      } 

      System.out.print(nb); 


     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 


    } 

다음은 내 데이터 집합입니다. 이 도움이

  ArffLoader testingData = new ArffLoader(); 
     testingData.setFile(new File("sample2.txt")); 
     Instances testingStructure = testingData.getStructure(); 
     testingStructure.setClassIndex(structure.numAttributes() - 1); 
     Instance test; 
     while ((test = testingData.getNextInstance(testingStructure)) != null) { 
      System.out.println(nb.classifyInstance(test)); 
     } 

희망 :

@relation weather 

@attribute outlook {sunny, overcast, rainy} 
@attribute temperature real 
@attribute humidity real 
@attribute windy {TRUE, FALSE} 
@attribute play {yes, no} 

@data 
sunny,85,85,FALSE,no 
sunny,80,90,TRUE,no 
overcast,83,86,FALSE,yes 
rainy,70,96,FALSE,yes 
rainy,68,80,FALSE,yes 
rainy,65,70,TRUE,no 
overcast,64,65,TRUE,yes 
sunny,72,95,FALSE,no 
sunny,69,70,FALSE,yes 
rainy,75,80,FALSE,yes 
sunny,75,70,TRUE,yes 
overcast,72,90,TRUE,yes 
overcast,81,75,FALSE,yes 
rainy,71,91,TRUE,no 

답변

1

별도의 테스트 세트에 대한 아래에 설명 된대로 classifyInstance 방법을 시도해 볼 수도 있습니다!

업데이트!

각 테스트 케이스의 확률 분포를 찾고있는 것처럼 들립니다. 아마도 아래 대신을 시도 할 수 :

  String[] options = new String[7]; 
     options[0] = "-t"; 
     options[1] = "sample.arff"; 
     options[2] = "-T"; 
     options[3] = "sample2.arff"; 
     options[4] = "-p"; 
     options[5] = "2"; 
     options[6] = "-distribution"; 

     System.out.println(Evaluation.evaluateModel(nb, options)); 

이 각각의 경우에 대한 확률 분포의 목록이 포함됩니다 (교육 자료 = sample.arff, 테스트 데이터 = sample2.arff, 확률 분포와 출력 테스트 예측)

+0

도움을 주셔서 감사합니다.이 부분은 이미 끝났습니다. 그래서 나는 내 가치관을 털어 놓고 확률을 확인하고 싶습니다. 내 가치관을 70,85, TRUE로 보내고 싶습니다. 응답을 얻으려고합니다. – Sajithv

+0

확률 분포를 출력 할 수있는 Evaluation.evaluateModel 클래스를 사용하여 내 대답을 수정했습니다. –

+0

도움을 주셔서 감사합니다. 나는 다른 것을 찾고 있습니다. 데이터 세트를 전송하고 있습니다. 그리고이 데이터를 기반으로 제 속성 세트의 클래스 값을 예측해야합니다. – Sajithv