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


Java Instance.setDataset方法代码示例

本文整理汇总了Java中weka.core.Instance.setDataset方法的典型用法代码示例。如果您正苦于以下问题:Java Instance.setDataset方法的具体用法?Java Instance.setDataset怎么用?Java Instance.setDataset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weka.core.Instance的用法示例。


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

示例1: Main

import weka.core.Instance; //导入方法依赖的package包/类
public Main() {
    try {
        BufferedReader datafile;
        datafile = readDataFile("camping.txt");
        Instances data = new Instances(datafile);
        data.setClassIndex(data.numAttributes() - 1);

        Instances trainingData = new Instances(data, 0, 14);
        Instances testingData = new Instances(data, 14, 5);
        Evaluation evaluation = new Evaluation(trainingData);

        SMO smo = new SMO();
        smo.buildClassifier(data);

        evaluation.evaluateModel(smo, testingData);
        System.out.println(evaluation.toSummaryString());

        // Test instance 
        Instance instance = new DenseInstance(3);
        instance.setValue(data.attribute("age"), 78);
        instance.setValue(data.attribute("income"), 125700);
        instance.setValue(data.attribute("camps"), 1);            
        instance.setDataset(data);
        System.out.println("The instance: " + instance);
        System.out.println(smo.classifyInstance(instance));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:30,代码来源:Main-SVG.java

示例2: classifySentence

import weka.core.Instance; //导入方法依赖的package包/类
public SentenceType classifySentence(Sentence sentence) {
	SpeechActsClassifier.Features features = speechActsClassifier.classifyFeatures(sentence);

	Instance inst = new DenseInstance(6);
	inst.setDataset(dataSet);

	inst.setValue(0, features.getSentenceLength());
	inst.setValue(1, features.getNumberOfNouns());
	inst.setValue(2, (features.isEndingInNounOrAdjective() ? 1 : 0));
	inst.setValue(3, (features.isBeginningInVerb() ? 1 : 0));
	inst.setValue(4, features.getCountOfWhMarkers());
	inst.setValue(5, Utils.missingValue());

	try {
		return SentenceType.valueOf(classifier.classifyInstance(inst));
	} catch (Exception e) {
		throw new RuntimeException("Can't classify");
	}
}
 
开发者ID:igr,项目名称:parlo,代码行数:20,代码来源:SentenceClassifier.java

示例3: classifyQuestion

import weka.core.Instance; //导入方法依赖的package包/类
public QuestionType classifyQuestion(Sentence sentence) {
	if (!sentence.isQuestion()) {
		return QuestionType.NA;
	}

	QuestionTypeClassifier.Features features = questionTypeClassifier.classifyFeatures(sentence);

	Instance inst = new DenseInstance(5);
	inst.setDataset(dataSet);

	inst.setValue(0, features.getWhWord());
	inst.setValue(1, features.getWhWordPos());
	inst.setValue(2, features.getPosOfNext());
	inst.setValue(3, features.getRootPos());
	inst.setValue(4, Utils.missingValue());

	try {
		int ndx = (int) classifier.classifyInstance(inst);
		 return QuestionType.valueOf(ndx);
	} catch (Exception e) {
		throw new RuntimeException("Not classified");
	}
}
 
开发者ID:igr,项目名称:parlo,代码行数:24,代码来源:QuestionClassifier.java

示例4: getInstanceObject

import weka.core.Instance; //导入方法依赖的package包/类
public static Instance getInstanceObject (String[] instanceText, 
        String[] globalFeatureVector, String docID, String classValue, Instances ds) throws Exception {
    
    FeatureVector instanceFeatureVector = getInstanceFeatureVector(instanceText, 
            globalFeatureVector, docID);
    
    
    Instance instance = new Instance(globalFeatureVector.length + 2);
    instance.setDataset(ds);
    instance.setValue(0, docID);
    for(int i = 0; i < globalFeatureVector.length; i++) {
    	double value = 0;
    	if(instanceFeatureVector.m_FeatureVector[0].containsKey(i)) {
    		value = instanceFeatureVector.m_FeatureVector[0].get(i);
    	}
    	
    	instance.setValue(i + 1, value);
    }
    instance.setValue(globalFeatureVector.length + 1, classValue);
    
    return new SparseInstance(instance);
}
 
开发者ID:NLPReViz,项目名称:emr-nlp-server,代码行数:23,代码来源:WekaDataSet.java

示例5: getTestInstance

import weka.core.Instance; //导入方法依赖的package包/类
private Instance getTestInstance(
        String binding, String multicolor, String genre) {
    Instance instance = new DenseInstance(3);
    instance.setDataset(trainingData);
    instance.setValue(trainingData.attribute(0), binding);
    instance.setValue(trainingData.attribute(1), multicolor);
    instance.setValue(trainingData.attribute(2), genre);
    return instance;
}
 
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:10,代码来源:BookDecisionTree.java

示例6: reloadSeries

import weka.core.Instance; //导入方法依赖的package包/类
private void reloadSeries(Number xValue, Number yValue) {
	try {
		Instance instance = new DenseInstance(NUMBER_OF_CLASSES);
		instance.setDataset(data);
		instance.setValue(0, xValue.doubleValue());
		instance.setValue(1, yValue.doubleValue());
		double predictedClass = tree.classifyInstance(instance);
		instance.setValue(2, predictedClass);
		data.add(instance);
		reloadSeries();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:jesuino,项目名称:java-ml-projects,代码行数:15,代码来源:Clustering.java

示例7: addExample

import weka.core.Instance; //导入方法依赖的package包/类
Instance addExample(IdentifiedInstances<Element> instances, EvaluationContext ctx, Element example, boolean train, boolean withId) {
	double[] values = evaluateExample(ctx, example, train);
	Instance inst = new Instance(1, values);
	if (withId)
		instances.add(example, inst);
	else
		instances.add(inst);
	inst.setDataset(instances);
	return inst;
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:11,代码来源:RelationDefinition.java


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