2014-07-15 5 views
3

2 개의 arff 파일을 병합하고 싶습니다. 속성은 같지만 속성의 값은 변경됩니다. 예를 들어Weka - 다른 헤더가있는 arff 파일 결합

는 :

3.arff: weather(sunny,rainy,warm,cold,freezing). 80 instances 

내가 샘플 CLI (웨카)에서 시도 : 그들 중

java weka.core.Instances 1.arff 2.arff > 3.arff 
java weka.core.Instances append 1.arff 2.arff > 3.arff 
java weka.core.Instances merge 1.arff 2.arff > 3.arff 

아무도 일하지

1.arff: weather(sunny, rainy). 50 instances 
2.arff: weather(warm, cold, freezing). 30 instances 

나는 새로운 arff을 만들려고합니다.

도움이 될 경우 고맙게 생각합니다.

대단히 감사합니다.

답변

0

MergeSets 클래스를 사용하여 파일을 병합 해 보았습니까? 당신은 여기에서 그것을 시도 할 수 있습니다 : http://bioweka.sourceforge.net/docs/api/bioweka/filters/universal/MergeSets.html

는 또한 두 arff 파일을 병합하는 작은 코드를 작성할 수 있습니다 :

import weka.core.converters.ArffLoader 
import java.io.{File,FileWriter} 

def combineAllArffs() { 
    var arffLoader = new ArffLoader 
    val arffDir: File = new File(s"Arff/") 

    val arffList = arffDir.listFiles; 
    var instances: Instances = null 
    var structure: Instances = null 

    if (arffList == null) { 
    print(s"Warning: Arff list for '$mode' is empty.") 
    return 
    } 

    for (arffFile <- arffList) { 
    arffLoader.setFile(arffFile) 
    if (instances == null) { 
     instances = arffLoader.getDataSet 
     structure = arffLoader.getStructure 
    } else { 
     var newInstances = arffLoader.getDataSet 
     var i = 0 
     while (i < newInstances.numInstances) { 
     val instance = newInstances.instance(i) 
     instances.add(instance) 
     i += 1 
     } 
    } 
    arffLoader.reset 
    } 

    val combinedFile = new File(s"Arff/Combined.arff") 
    val fw = new FileWriter(combinedFile) 
    fw.write(instances.toString) 
    fw.close 
} 

이 귀하의 경우에 작동합니다.

0

며칠 전 동일한 문제가 발생하여 파이썬으로 작은 스크립트를 작성했습니다. Here 찾을 수 있습니다.