如何从arff文件中删除特定属性并生成修改后的arff? [英] How to remove particular attributes from arff file and produce modified arff?

查看:223
本文介绍了如何从arff文件中删除特定属性并生成修改后的arff?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(不是手动的),我有96个功能,并且想从arff中删除一些20个功能并产生修改后的arff。使用weka进行特征选择的用户现在想要删除那些不太重要的imp功能。谁能为此建议代码

(not manually) i have 96 features and want to remove some 20 features from arff and produce modified arff. used weka for feature selection now want to remove those less imp features. can anyone suggest code for this

推荐答案

在这里,只需更改源文件和目标文件的路径...

Here you go... just change the source and destination file path...

import java.io.File;
import weka.core.Instances;
import weka.core.converters.ArffLoader;
import weka.core.converters.ArffSaver;
import weka.filters.Filter;
import weka.filters.unsupervised.attribute.Remove;


public class Convert4 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try
        {
            ArffLoader loader2= new ArffLoader();
            loader2.setSource(new File("C:/Users/RAHUL/Desktop/stack.arff"));
            Instances data2= loader2.getDataSet();
            //Load Arff
             String[] options = new String[2];
             options[0] = "-R";                                    // "range"
             options[1] = "1";                                     // first attribute
             Remove remove = new Remove();                         // new instance of filter
             remove.setOptions(options);                           // set options
             remove.setInputFormat(data2);                          // inform filter about dataset **AFTER** setting options
             Instances newData2 = Filter.useFilter(data2, remove);   // apply filter
             ArffSaver saver = new ArffSaver();
             saver.setInstances(newData2);
             saver.setFile(new File("C:/Users/RAHUL/Desktop/stack2.arff"));
             saver.writeBatch();
}
catch (Exception e)
{}
}
}

干杯:)

这篇关于如何从arff文件中删除特定属性并生成修改后的arff?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆