2012-11-30 4 views
0

WEKA에서 간단한 naes 베이 분류자를 가지고 있습니다. 나는 디렉토리 구조를 사용하고 TextDirectoryLoader를 통해 그것을 읽는다. 디렉토리 구조는Java 코드의 WEKA 분류 자에서 분배의 범주 이름을 얻는 방법

Training_Data 
    Spam (folder) 
     text files 
    Ham (folder) 
     text files 

내가 좋아 분포를 얻을 수있다이

for(Instance i: testInstances){ 

    double [] distributions = classifier.distributionForInstance(i); 
    for(double d : distributions) 
     System.out.println(d); 
} 

제가하고 싶은 것은 카테고리 이름이 측면을 따라 갈 수 분포가 그래서 그렇게

처럼 인쇄 할 수 있습니다
System.out.println("Category: "+/*something to get the category name*/+ ":"+ d); 

나는 지금 몇 시간 씩보고 있었고 그 방법을 알 수 없습니다. 누구나 어떻게 알아?

답변

1

당신은 valIndex이 카테고리의 인덱스 instance.classAttribute().value(valIndex) 사용할 수 있습니다

for(Instance i: testInstances){ 
    double [] distributions = classifier.distributionForInstance(i); 
    for(int index = 0; index < distributions.length; index++) 
     System.out.println(i.classAttribute().value(index) + ": " + distributions[index]); 
} 
+0

감사합니다, 매력처럼 일 – triggs

관련 문제