首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何访问标记为j48的数据?

如何访问标记为j48的数据?
EN

Stack Overflow用户
提问于 2017-10-07 17:50:51
回答 2查看 137关注 0票数 0
代码语言:javascript
复制
import javax.print.attribute.DateTimeSyntax;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
import weka.classifiers.bayes.NaiveBayes;
import weka.classifiers.trees.J48;
import weka.classifiers.functions.SMO;
public class Classification {
    public static void main(String[] args) throws Exception{
        //load dataset
        DataSource source = new DataSource("j:/weka/wekadataset/iris.arff");
        Instances dataset = source.getDataSet();
        // set the class to the last class attribute
        dataset.setClassIndex(dataset.numAttributes()-1);
        //create and build classifier
        J48 tree= new J48();
        tree.buildClassifier(dataset);
    }
}

//我在半监督学习中使用J48。每次迭代之后,我必须访问标记的数据,以便在下一次迭代中使用它。,我的问题在这里。如何访问每个步骤的标记数据?.我应该修改J48源代码,这样我才能看到它或者有办法做到这一点(在Java中,有方法吗?)

EN

回答 2

Stack Overflow用户

发布于 2017-10-24 20:13:57

代码语言:javascript
复制
//write the modified dataset by j48 into the new file and
// write in the output
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
    for (int i=0; i<k ; i++){
        Instance newInstance = instance01.instance(i);
        //write attributes 
        for(int j=0;j<newInstance.numAttributes()-1;j++){
            String AttribValue =Double.toString(newInstance.value(j));
            System.out.print(newInstance.value(j)+"-");
            bw.write(AttribValue+",");
        }
        //write the class
        double actualClass = tree.classifyInstance(newInstance);
        String actual =newInstance.classAttribute().value((int)actualClass);
        System.out.println("class="+actual);
        bw.write(actual);
        bw.newLine();
    }
    bw.close();
票数 0
EN

Stack Overflow用户

发布于 2017-10-24 20:24:49

代码语言:javascript
复制
//now compare the source file and the modified dataset in the second
//file. write the differences in the third file and then rename this file
//to the second file
FileOutputStream fos1 = new FileOutputStream(new File
        ("j:/weka/wekadataset/new folder/iris-semi02.arff"));//third file
BufferedWriter bw1 = new BufferedWriter(new OutputStreamWriter(fos1));
BufferedReader br1 = new BufferedReader(new FileReader(
        "j:/weka/wekadataset/iris-semi.arff"));//
BufferedReader br2 = new BufferedReader(new FileReader(
        "j:/weka/wekadataset/new folder/iris-semi01.arff"));
String line1=br1.readLine();
String line2=br2.readLine();
while(!line1.startsWith("@DATA")){line1=br1.readLine();}
    line1=br1.readLine();   
    while(line1!=null && line2!=null ){
        if(!line1.equals(line2)){ 
            bw1.write(line2);   
            bw1.newLine();
        }
        line1=br1.readLine();
        line2=br2.readLine();
}
bw1.close();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46623303

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档