当前位置: 首页>>代码示例>>Java>>正文


Java ArffSaver类代码示例

本文整理汇总了Java中weka.core.converters.ArffSaver的典型用法代码示例。如果您正苦于以下问题:Java ArffSaver类的具体用法?Java ArffSaver怎么用?Java ArffSaver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ArffSaver类属于weka.core.converters包,在下文中一共展示了ArffSaver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: saveInstancesToArffFile

import weka.core.converters.ArffSaver; //导入依赖的package包/类
public File saveInstancesToArffFile(Instances instances, String filename) throws IOException
{
    LOGGER.trace("Saving data to ARFF file [{}].", filename);

    File outputFile = new File(filename);
    if (outputFile.exists())
    {
        outputFile.delete();
        outputFile.createNewFile();
    }

    ArffSaver arffSaver = new ArffSaver();
    arffSaver.setInstances(instances);
    arffSaver.setFile(outputFile);
    arffSaver.writeBatch();

    return arffSaver.retrieveFile();
}
 
开发者ID:marcelovca90,项目名称:anti-spam-weka-gui,代码行数:19,代码来源:InputOutputHelper.java

示例2: main

import weka.core.converters.ArffSaver; //导入依赖的package包/类
/**
 * Main method for testing this class.
 * 
 * 
 *            should contain the path of input dataset and the name of
 *            target file scheme (see Evaluation)
 *@param args arguments            
 */
static public void main(String args[]) {

	if (args.length == 2) {

		TweetCollectionToArff ta = new SemEvalToArff();

		try {
			Instances dataset = ta.createDataset(args[0]);
			ArffSaver saver = new ArffSaver();
			saver.setInstances(dataset);

			saver.setFile(new File(args[1]));
			saver.writeBatch();

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

	}

}
 
开发者ID:felipebravom,项目名称:AffectiveTweets,代码行数:31,代码来源:SemEvalToArff.java

示例3: main

import weka.core.converters.ArffSaver; //导入依赖的package包/类
/**
 * Main method for testing this class.
 * 
 * should contain the path of input dataset and the name of
 *            target file scheme (see Evaluation)
 * @param args arguments           
 */
static public void main(String args[]) {

	if (args.length == 2) {

		TweetCollectionToArff ta = new HumanCodedToArff();

		try {
			Instances dataset = ta.createDataset(args[0]);
			ArffSaver saver = new ArffSaver();
			saver.setInstances(dataset);

			saver.setFile(new File(args[1]));
			saver.writeBatch();

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

	}

}
 
开发者ID:felipebravom,项目名称:AffectiveTweets,代码行数:30,代码来源:HumanCodedToArff.java

示例4: shuffle

import weka.core.converters.ArffSaver; //导入依赖的package包/类
public static void shuffle(String file, int classindex, String outputFile)
		throws IOException {

	// create the stream to read the data
	ArffFileStream stream = new ArffFileStream(file, classindex);
	InstancesHeader header = stream.getHeader();
	ArrayList<Instance> instanceList = new ArrayList<Instance>();
	System.out.println("Loading data ...");
	int cnt = 0;
	while (stream.hasMoreInstances()) {
		if (++cnt % 10000 == 0) {
			System.out.println("Read " + cnt + " items.");
		}
		instanceList.add(stream.nextInstance());
	}
	System.out.println("Read all items ... shuffling.");
	Collections.shuffle(instanceList);
	ArrayList<Attribute> attributeList = new ArrayList<Attribute>();
	for (int i = 0; i < header.numAttributes(); i++) {
		attributeList.add(header.attribute(i));
	}
	Instances dataSet = new Instances("reduced", attributeList, 2);
	for (Instance inst : instanceList) {
		dataSet.add(inst);
		inst.setDataset(dataSet);
	}
	System.out.println("Writing output ...");
	ArffSaver saver = new ArffSaver();
	saver.setInstances(dataSet);
	saver.setFile(new File(outputFile));
	saver.writeBatch();
	System.out.println("Done.");
}
 
开发者ID:yahoo,项目名称:anthelion,代码行数:34,代码来源:DataSetShuffler.java

示例5: reduce

import weka.core.converters.ArffSaver; //导入依赖的package包/类
@Override
public void reduce(Iterable<WikiDocumentOutput> values, Collector<EvaluationResult> out) throws Exception {
  Instances instances;
  DependencyParser parser = DependencyParser.loadFromModelFile(config.dependencyParserModel());
  WekaUtils wekaUtils = new WekaUtils();
  instances = wekaUtils.createInstances("AllRelations");
  for (WikiDocumentOutput value : values) {
    wekaUtils.addRelationsToInstances(parser, value.getRelations(), value.getTitle(), value.getqId(), instances, value.getMaxSentenceLength());
  }
  if (config.isWriteInstances()) {
    File instancesFile = new File(config.getOutputDir() + INSTANCES_ARFF_FILE_NAME);
    ArffSaver arffSaver = new ArffSaver();
    arffSaver.setFile(instancesFile);
    arffSaver.setInstances(instances);
    arffSaver.writeBatch();
  }
  //do model once with all data
  if (config.getWriteSvmModel()) {
    generateAndWriteFullModel(instances);
  }
  process(out, instances);
}
 
开发者ID:ag-gipp,项目名称:mathosphere,代码行数:23,代码来源:WekaLearner.java

示例6: dump_from_scratch

import weka.core.converters.ArffSaver; //导入依赖的package包/类
/**
 *  When the score changes, rewrite the file.
 *  This is really rare in practice, so don't bother optimizing it.
 */
private static void dump_from_scratch(Collection<String> names, Timestamp start_time) throws IOException {
	saved_schema_version = names.size();
	
	FastVector attributes = new FastVector();
	// Answer score names
	for (String name: names)
		attributes.addElement(new Attribute(name));
	Instances data = new Instances("Watsonsim captured question stream", attributes, 0);
	
	// Save the results to a file
	saver = new ArffSaver();
	saver.setStructure(data);
	saver.setRetrieval(Saver.INCREMENTAL);
	saver.setFile(new File("data/weka-log." + start_time + ".arff"));
	for (Score row : dataset)
		saver.writeIncremental(new Instance(1.0, row.getEach(names)));
}
 
开发者ID:SeanTater,项目名称:uncc2014watsonsim,代码行数:22,代码来源:WekaTee.java

示例7: CSVtoARFF

import weka.core.converters.ArffSaver; //导入依赖的package包/类
public static void CSVtoARFF(String csvfilename, String arfffilename) {
    try {
        // load CSV
        CSVLoader loader = new CSVLoader();
        loader.setSource(new File(csvfilename));
        Instances data = loader.getDataSet();

        // save ARFF
        ArffSaver saver = new ArffSaver();
        saver.setInstances(data);
        saver.setFile(new File(arfffilename));
        saver.setDestination(new File(arfffilename));
        saver.writeBatch();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:frank0631,项目名称:semantic-web-scraper,代码行数:18,代码来源:semanticWebScraper.java

示例8: main

import weka.core.converters.ArffSaver; //导入依赖的package包/类
/**
  * takes 2 arguments:
  * - CSV input file
  * - ARFF output file
  */
public static void main(String[] vagina) throws Exception {
	String[] args = {"trainingSet.csv","penis.arff"};

	// load CSV
	CSVLoader loader = new CSVLoader();
	loader.setSource(new File(args[0]));
	Instances data = loader.getDataSet();

	// save ARFF
	ArffSaver saver = new ArffSaver();
	saver.setInstances(data);
	File penis = new File(args[1]);
	saver.setFile(penis);
	//    saver.setDestination(penis);
	saver.writeBatch();
}
 
开发者ID:zpankr,项目名称:SmartBetSystem,代码行数:22,代码来源:CSV2Arff.java

示例9: buildTrainingDataFromCorpus

import weka.core.converters.ArffSaver; //导入依赖的package包/类
public static void buildTrainingDataFromCorpus(String dataSetName,
        File corpusRoot, FVGenerator fvGenerator, File dest)
        throws IOException {
    Collection<File> children = FileUtils.listFiles(corpusRoot,
            new RegexFileFilter(".+\\.txt", IOCase.INSENSITIVE), DirectoryFileFilter.INSTANCE);

    ArffSaver saver = new ArffSaver();
    saver.setFile(dest);
    saver.setRetrieval(Saver.INCREMENTAL);
    boolean first = true;
    for (File textFile : children) {

        Instances dataSet = buildTrainingDataFromFile(dataSetName, textFile, fvGenerator);

        if (first) {
            saver.setStructure(dataSet);

            first = false;
        }
        for (int i = 0; i < dataSet.numInstances(); ++i) {
            saver.writeIncremental(dataSet.instance(i));
        }

    }
    saver.getWriter().flush();
}
 
开发者ID:wittawatj,项目名称:ctwt,代码行数:27,代码来源:Actions.java

示例10: convertToArff

import weka.core.converters.ArffSaver; //导入依赖的package包/类
public static Instances convertToArff(List<Document> dataSet, List<String> vocabulary, String fileName) {
    int dataSetSize = dataSet.size();
    /* Create features */
    ArrayList<Attribute> attributes = new ArrayList<>();
    for (int i = 0; i < vocabulary.size(); i++) {
        attributes.add(new Attribute("word_" + i));
    }
    Attribute classAttribute = new Attribute("Class");
    attributes.add(classAttribute);

    /* Add examples */
    System.out.println("Building instances...");
    Instances trainingDataSet = new Instances(fileName, attributes, 0);
    for (int k = 0; k < dataSetSize; k++) {
        Document document = dataSet.get(k);
        Instance example = new DenseInstance(attributes.size());
        for (int i = 0; i < vocabulary.size(); i++) {
            String word = vocabulary.get(i);
            example.setValue(i, Collections.frequency(document.getTerms(), word));
        }
        example.setValue(classAttribute, document.getDocumentClass());
        trainingDataSet.add(example);
        int progress = (int) ((k * 100.0) / dataSetSize);
        System.out.printf("\rPercent completed: %3d%%", progress);
    }
    trainingDataSet.setClass(classAttribute);
    System.out.println();

    System.out.println("Writing to file ...");
    try {
        ArffSaver saver = new ArffSaver();
        saver.setInstances(trainingDataSet);
        saver.setFile(new File(fileName));
        saver.writeBatch();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return trainingDataSet;
}
 
开发者ID:MarkXLII,项目名称:CS-436_580L_Introduction-to-Machine-Learning,代码行数:41,代码来源:Utils.java

示例11: saveDataToArffFile

import weka.core.converters.ArffSaver; //导入依赖的package包/类
/**
 * Save @param data to the Arff file at @param path
 */
public static void saveDataToArffFile(String path, Instances data) throws IOException{
	    System.out.println("\nSaving to file " + path + "...");
	    ArffSaver saver = new ArffSaver();
	    saver.setInstances(data);
	    saver.setFile(new File(path));
	    saver.writeBatch();
}
 
开发者ID:zhuyuqing,项目名称:bestconf,代码行数:11,代码来源:DataIOFile.java

示例12: generateArff

import weka.core.converters.ArffSaver; //导入依赖的package包/类
public void generateArff() throws Exception{
	
	//
	CSVLoader loader = new CSVLoader();
	// Set options
	loader.setNominalAttributes("last");
	loader.setStringAttributes("");
	loader.setMissingValue("?");
	loader.setFieldSeparator("\t");
	loader.setFile(new File(seqConfig.getOutDir().getAbsolutePath()+File.separator+"tmpCounts.mat"));
	Instances data = loader.getDataSet();
	
	//Set subgroup index
	if(data.classIndex() == -1)
		data.setClassIndex(data.numAttributes()-1);
	
	//First, get weight index
	int wInd = data.numAttributes()-2;
	// Now set weights
	for(int i=0; i<data.numInstances(); i++){
		double weight = data.instance(i).value(wInd);
		data.instance(i).setWeight(weight);
	}
	// Now delete the weight attribute
	data.deleteAttributeAt(wInd);
	
	//Save the arff file
	ArffSaver saver = new ArffSaver();
	saver.setFile(new File(seqConfig.getOutDir().getAbsolutePath()+File.separator+seqConfig.getArffOutName()));
	saver.setInstances(data);
	saver.writeBatch();
	
	
}
 
开发者ID:seqcode,项目名称:sequnwinder,代码行数:35,代码来源:MakeArff.java

示例13: saveInstancesToArff

import weka.core.converters.ArffSaver; //导入依赖的package包/类
public static void saveInstancesToArff(Instances instances, String path) throws ClassifierException {
    try {
        ArffSaver arffSaver = new ArffSaver();
        arffSaver.setInstances(instances);
        File destination = new File(path);
        arffSaver.setFile(destination);
        arffSaver.writeBatch();
    } catch (IOException e) {
        throw new ClassifierException("Saving arff file failed", e);
    }
}
 
开发者ID:sasinda,项目名称:OntologyBasedInormationExtractor,代码行数:12,代码来源:ArffUtil.java

示例14: saveFoldFiles

import weka.core.converters.ArffSaver; //导入依赖的package包/类
protected void saveFoldFiles(Instances Training_Instances, int i, Instances Testing_Instances) throws IOException {
    // Store instances to related fold files in ARFF subdir (WARNING: It must exist)
    ArffSaver asSaver = new ArffSaver();
    asSaver.setInstances(Training_Instances);
    asSaver.setFile(new File(String.format("ARFF/train-fold%d.arff", i)));
    asSaver.writeBatch();
    
    asSaver.setInstances(Testing_Instances);
    asSaver.setFile(new File(String.format("ARFF/test-fold%d.arff", i)));
    asSaver.writeBatch();
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:12,代码来源:RunHandler.java

示例15: CSVToARFF

import weka.core.converters.ArffSaver; //导入依赖的package包/类
public static void CSVToARFF(File input, File output) throws IOException {
    CSVLoader csvDataset = new CSVLoader();
    csvDataset.setSource(input);
    Instances arffDataset = csvDataset.getDataSet();
    ArffSaver saver = new ArffSaver();
    saver.setInstances(arffDataset);
    saver.setFile(output);
    saver.writeBatch();
}
 
开发者ID:FlorentinTh,项目名称:SpeakerAuthentication,代码行数:10,代码来源:FileUtils.java


注:本文中的weka.core.converters.ArffSaver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。