當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。